Replies: 2 comments 6 replies
-
Your side-effectful effects are not really concatenated. The three The concatenation of the effects in your case can be achieved by concatenating actual jobs, like:
Is there any reason for you to have the |
Beta Was this translation helpful? Give feedback.
-
I was surprised by that behavior of
That is very unfortunate and confusing. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I'm currently hitting a bit of a wall with regards to the
concatenate
function onEffect
.In the app I'm working on, we need to make multiple API calls on launch. The order of the API call responses really matters, as they return data that we write to our database, for which foreign keys matter. i.e. The first API call might return some Foo instances, which need to be written before the next API call's Bar instances are written, as the Bar has an ID field referencing a Foo, which might not be present in the database if they're not written in the correct order.
We're currently wrapping all our action up into a
concatenate
, as the documentation says it dispatches Effects one after the other. However, it doesn't seem to wait for the previousEffect
to complete before sending the nextEffect
. Due to the size of the responses, the network, or whatever, the order in which we send the actions isn't necessarily the order in which we receive them. i.e. we might get the Bar response before the Foo response, which causes havoc with our database.I know we could probably wrap this up into a dependency, with just one call from the Reducer, but this seems to fly against the testability enabled by TCA. I've personally already made that choice once before, when juggling API calls and database writes, and I'd just like to know if there's a better way using the tools TCA/Combine already gives us?
I've put a sample project up showing exactly what I mean here: TCA-ActionChain
I've simulated the API async nature by adding a random delay onto each response action.
If anyone has any ideas, I'd greatly appreciate them!
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions