Skip to content

Testing parallel effects #3366

Closed Answered by mbrandonw
m-makhovyk asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @m-makhovyk, it is not necessary to spin up an unstructured task to send actions "in parallel":

// ❌ Not recommended
Task {
  await store.send(.setValue(value: 10, delay: 1))
}
Task {
  await store.send(.setValue(value: 20, delay: 0))
}

The await in TestStore's send doesn't mean "await until action and effects complete". It just means "await until action is processed and effects start."

This means you can typically just do this:

await store.send(.setValue(value: 10, delay: 1))
await store.send(.setValue(value: 20, delay: 0))
await store.receive(\.valueSet, 20, timeout: 5)
await store.receive(\.valueSet, 10, timeout: 5)

However, another problem with your code is that you have hardcoded …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by m-makhovyk
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants