![]() async(.) creates an asynchronous task to run withTaskGroup(.) so you can actually use await inside the closure body,.compute() is not async anymore and returns an AnyPublisher so consumers can subscribe and observe the progress,.It took some trial and error to come up with this code but here’s the play-by-play: The compute() function from part 1 which precomputes a bunch of hashes and adds them to the cache currently looks like so:Īwait withTaskGroup(of: Bool. Huge disclaimer: This post is purely exploratory and is using the experimental Swift concurrency feature which is a work in progress. So let’s add some Combine to the ActorTest app from part 1! Converting an async function to synchronous In fact, I think it’s great we’re getting a simpler way of async/concurrent for simple tasks and still have the option to solve more complex problems with Combine. In any case I think the Combine APIs to manage multiple streams of events over time offer a unique angle to asycnhronous value processing. Reimplementing publishers that only emit series of values and then complete as an AsyncSequence will be easier and more importantly much simpler at the point-of-use.I believe I won’t use Future much more since an async function is much simpler to write.What’s more the new concurrency APIs are fully integrated with Swift’s error handling which makes the code much simpler to write and read. Some simple use cases would be easier with the new APIs. With all the concurrency advancements like async/await, the Task APIs, and actors - is Combine going to be still needed? When I wrapped up writing part 1, I was looking at my new cache actor and I started wondering “ What about Combine?”. If you missed part 1, definitely do read it first as this post builds upon the code I already covered there. In my previous post Swift Actors: A practical example, part 1 I covered how I got a toolchain from trunk, enabled support for the currently experimental support for structured concurrency, and created a thread-safe cache in few lines of Swift code. An assert operator: assertMaxSubscriptions().Binding a list with multiple sections and different cells.How to create a custom instrument on top of Timelane!.5 Stranger Things you can do with Timelane at NSSpain.Using self, weak, and unowned in Combine.Swift Actors: A practical example, part 1.Swift Actors: A practical example, part 2.Bridge from Combine to AsyncSequence - the plan (p.Bridge from Combine to AsyncSequence - the code (p.The difference between Thread.sleep() and Task.sleep().Actors, the cooperative pool and concurrency.Announcing: “Modern Concurrency in Swift”. ![]() Swift Async Sequence extensions (part 1).Swift Async Sequence extensions (part 2).The issue with task groups or how I discovered a solved problem.dataTile for Simulator - public beta on TestFlight now!.Custom SwiftUI view modifier for paid app features.Automation tooling using MarkCodable for reports.dataTile for Simulator launches today! □.Automate debugging SwiftUI and UIKit with dataTile. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |