Skip to content

Wait for asynchronous event change after sending an event #4993

Closed Answered by crishoj
drFabio asked this question in Q&A
Discussion options

You must be logged in to vote

@drFabio you might find the waitFor helper useful:

await waitFor(exampleActor, (state) => state.matches('Inserted'))

Timeout is configurable (default 10s).

In my experience, this means that a failed actor won't immediately result in a rejected waitFor promise. If you want waitFor to abort as soon as the actor reaches the Failure state, you can expand the awaited predicate with a throw:

await waitFor(exampleActor, (state) => {
  if (state.matches('Failure')) throw new Error('Insert failed')
  state.matches('Inserted')
})

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@drFabio
Comment options

Answer selected by drFabio
Comment options

You must be logged in to vote
2 replies
@crishoj
Comment options

@drFabio
Comment options

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