Has anyone successfully adapted CocoaAsyncSocket (TCP and / or UDP) to support async / await? I’ve used CocoaAsyncSocket for the last few years in my apps and would like to simplify the apps by eliminating the delegate usage and replace it with async / await.
Asked
Active
Viewed 105 times
1
-
See [Swift concurrency: Update a sample app](https://developer.apple.com/videos/play/wwdc2021/10194/) which, amongst other things, shows how to wrap existing asynchronous API via `withCheckedThrowingContinuation`, providing Swift concurrency interface for legacy asynchronous API. – Rob Jun 08 '22 at 19:03
-
Actually thinking about it, `withCheckedThrowingContinuation` is useful when wrapping a completion handler-based API. But if you’ve got a delegate-based API (e.g. called every time you have new message), you probably want `AsyncSequence`, e.g. `AsyncStream`. See [Meet AsyncSequence](https://developer.apple.com/videos/play/wwdc2021/10058/). – Rob Jun 09 '22 at 00:45
-
1I agree, AsyncSequence is probably the correct approach. I've been using CocoaAsyncSocket for years. A version supporting Async/Await and AsyncSequence would be great. – DougPA Jun 24 '22 at 21:11