Questions tagged [asyncstream]

AsyncStream is a Swift concurrency type that is an asynchronous sequence generated from a closure that calls a continuation to produce new elements.

AsyncStream is a Swift concurrency type that is an asynchronous sequence generated from a closure that calls a continuation to produce new elements.

AsyncStream conforms to AsyncSequence, providing a convenient way to create an asynchronous sequence without manually implementing an asynchronous iterator. In particular, an asynchronous stream is well-suited to adapt callback- or delegation-based APIs to participate with async-await.

See also

8 questions
3
votes
1 answer

Use NWPathMonitor with Swift Modern Concurrency (AsyncStream) vs GCD (DispatchQueue)

I have noticed that the start(queue:) method in NWPathMonitor requires a queue of type DispatchQueue. Is there a way to implement this using Swift Modern Concurrency, probably using AsyncStream? Using Apple documentation for AsyncStream, I have…
logicito
  • 141
  • 4
2
votes
2 answers

TaskGroup limit amount of memory usage for lots of tasks

I'm trying to build a chunked file uploading mechanism using modern Swift Concurrency. There is a streamed file reader which I'm using to read files chunk by chunk of 1mb size. It has two closures nextChunk: (DataChunk) -> Void and completion: () -…
1
vote
1 answer

AsyncStream spams view, where AsyncPublisher does not

I'm running into a behavior with AsyncStream I don't quite understand. When I have an actor with a published variable, I can "subscribe" to it via an AsyncPublisher and it behaves as expected, updating only when there is a change in value. If I…
carlynorama
  • 166
  • 7
1
vote
2 answers

Issues with retain cycle using AsyncStream in a Task

Found this issue while working with the new Swift concurrency tools. Here's the setup: class FailedDeinit { init() { print(#function, id) task = Task { await subscribe() } } deinit { …
Steve Begin
  • 225
  • 1
  • 8
0
votes
1 answer

How to use Swift's AsyncThrowingStream with Firestore Listeners

How can I convert this code to use AsyncThrowingStream private var listenerRegistration: ListenerRegistration? func unsubscribe() { if listenerRegistration != nil { listenerRegistration?.remove() …
byaruhaf
  • 4,128
  • 2
  • 32
  • 50
0
votes
1 answer

AsyncStream not executing closure

so I'm reading the Modern Concurrency book from raywenderlich.com and I assume the book must be outdated or something, I'm trying to run the closure insde the AsyncStream but it doesn't seem to get there, I'm still pretty new to this Async/Await…
0
votes
0 answers

publishing value of NSObject by KeyPath using AsyncStream - reference cycle problem

I'm plaing with concurrency features of Swift. I've created helper function which returns AsyncStream with values published by NSOBject implementations. Sort of code below. func asyncStreamFor (_ root: Root, keyPath:…
0
votes
0 answers

Two async streams, one inside of the other

I have two async streams. The first is PathMonitorClient that simply streams NWPath.Status. The second is a databaseClient that publishes my database changes. I want to only upload my database changes when NWPath.Status == .satisfied. Here is my…
Nate Mann
  • 695
  • 6
  • 17