Skip to content
Discussion options

You must be logged in to vote

Hi @piojost, when using the ifLet operator, all child effects are automatically canceled when child state is nil'd out, and so you can use this knowledge in your dependency to do any necessary tear down. For example, a play endpoint on an AudioPlayerClient could listen for cancellation to automatically stop:

play: { url in 
  await withTaskCancellationHandler {
    await player.play()
  } onCancel: {
    player.stop()
  }
}

This does require your dependency to be a little more deeply ingrained with Swift concurrency, but that has other benefits too. For example, in the above code, the player.play needs to be async and suspend for as long as the audio is playing. That allows you to tie the…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@piojost
Comment options

@mbrandonw
Comment options

@piojost
Comment options

Answer selected by piojost
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