Skip to content
Discussion options

You must be logged in to vote

Hey @andwrobs! In this simple case, you should probably fence your .run block with (begin|end)BackgroundTask:

return .run { send in
  let backgroundTaskID = await UIApplication.shared.beginBackgroundTask(withName: "\(Self.self)")
  // Perform your work
  try await mainQueue.sleep(for: .milliseconds(500))
  await UIApplication.shared.endBackgroundTask(backgroundTaskID)
}

This will grant you a little more execution time (around 30s AFAIK). There is a variant for extensions which can't touch UIApplication.shared. If you need more time, there are more complex background operation APIs, but this one should work.

Beware though, send doesn't await for the effects produced by the emitted action t…

Replies: 1 comment 1 reply

Comment options

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

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