What do I do if I have no choice but to call a blocking API (from an
actor)?
I don’t think there’s a good answer to this right now [1]. Then again, there isn’t a good answer to this in the Dispatch world either. I’ve seen a lot of code that does this by dispatching to a concurrent queue and then blocking there, ignoring the wider impact of that choice.
As to what you can do right now, that depends on the nature of this API and your use pattern. For example, if there’s some heavyweight API that’s going to block for a long period of time and that I call infrequently, I may well do this using a thread; that avoids consuming a worker thread (either Dispatch or Swift concurrency) and gives me full control over any thread explosion. In contrast, if I expect this API to block for a short period of time and I call it frequently, I might use a Dispatch serial queue. Regardless, withCheckedContinuation(…)
would get me out and then back in to Actor Space™.
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple
[1] I suspect that the answer will come from the custom executor space but, speaking for myself, I can only discuss what is, not what might be.