How to currently offload stateless blocking work? Hidden executor API?

to clarify are you talking about when it’s used within a continuation?
Or always?

Both (-:

In that quote I was referring to your specific usage. My concern wasn’t about the context but rather the ‘weight’ of someHeavyStatelessBlockingFunctionTaking10Seconds(). That’s completely inappropriate for a Dispatch concurrent queue.

Stepping back, Dispatch concurrent queues are almost always the wrong answer. In some cases they’re expedient and relatively safe. For example, if you have a very lightweight closure that needs to run somewhere and you don’t care where, it’s generally OK to use a concurrent queue. In most other cases, however, using them is like planting a landmine: Sooner or later someone is going to get hurt.

If you want to understand Dispatch, I strongly recommend that you watch the WWDC videos I referenced above. And if you’re interested in the Swift concurrency side of this, add WWDC 2021 Session 10254 Swift concurrency: Behind the scenes to your playlist. All three are presented by members of the Dispatch team, offering advice based on hard-won experience.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

6 Likes