Skip to content

Sequential async void functions #1541

Answered by mbrandonw
coenttb asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @tenthijeboonkkamp, the await inside the Effect.run represents the async work to send the action on the main actor, not the lifecycle of the effect that is produced from sending the action.

You can even confirm this by annotating the closure with @MainActor and seeing that you no longer have to await at all:

return .run { @MainActor in send in
  send(.print(.clearDocuments))
  send(.print(.print))
  send(.printCompleted)
}

This shows that the 3 actions are sent one after another synchronously, regardless of what logic and effects are being executed for each action.

Is there a reason you have separated all of these steps into actions? Can it all be done in a single action and a single e…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by coenttb
Comment options

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

@coenttb
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