Skip to content

Support await / AsyncSequence #830

Description

@NachoSoto

I haven’t tried the new betas yet, but I imagine the prevalence of @MainActor in iOS 15 will bring issues to current uses of ReactiveSwift.
Specifically, I imagine you won’t be able to just do this:

producer
  .observe(on: UIScheduler())
  .start { [label] in label.text = $0  }

Feature request:

for await value in producer.start() {
  self.label.text = value
}

Unfortunately for try await would mean we lose error type information, so I would propose this API produces Result<Value, Error>, or a sequence of Value if Error is Never.

I’ll probably work on this throughout the week, but other thoughts are appreciated!

References:

Other ideas:

  • Being able to create SignalProducers using async:
SignalProducer<Int, MyError> { observer, disposable in
  observer.send(value: await f1())

  guard !disposable.isDisposed else { return }

  do {
    observer.send(value: try await f2())
  } catch {
    observer.send(error: error)
  }
}
  • Or simply just one async function:
let producer = SignalProducer<Int, Error>(asyncFunction: f)
  • New collect overloads:
let values: [Int] = await producer.collect()
let result: Result<[Int], MyError> = try await producer.collect()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions