Skip to content
Discussion options

You must be logged in to vote

Hi @vctxr, if you can use version 0.39.0 or later of the library, then this can automatically be handled for you via Swift's concurrency tools.

Rather than using .onAppear you need to use SwiftUI's .task view modifier, which allows you to perform some asynchronous work when the view appears, and that work will automatically be cancelled when the view goes away.

So, rather than having an onAppear action that uses a Combine timer, you can have a .task action that makes use of an async/await timer:

case .task: 
  return .run { send in 
    for await _ in DispatchQueue.main.timer(interval: .seconds(1)) {
      await send(.receiveLongLivingEffect)
    }
  }

And then you can await sending that …

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@vctxr
Comment options

@jslew
Comment options

@mbrandonw
Comment options

@stephencelis
Comment options

@jslew
Comment options

Answer selected by vctxr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants