> On Aug 31, 2017, at 11:35 AM, Joe Groff via swift-evolution
> <[email protected]> wrote:
>
> # Coroutine context
>
> # `onResume` hooks
`onResume` hooks seem like a really good way to, essentially, allow arbitrary
concurrency primitives to be passed into `async` functions. My main question
is, if we have it, why do we need coroutine contexts? It seems to me that
anything the coroutine might do with the context could either be passed into
its parameters, or encapsulated in its `onResume` hook.
> and also prevents writing APIs that intentionally change context across an
> `await`, like a theoretical "goToMainThread()" function
You say that like it's a bad thing. :^)
(Seriously, I feel like that makes it *way* too easy to jump to another thread
in the middle of a function using what looks like an ordinary line of code. A
`let result = await someQueue.async { … }` syntax is a lot clearer that you're
hopping to another thread and about what code will run on it, but can get
around our current "pyramid of doom" problem. If the async syntax guarantees
that the code before and after the `await` runs in the same
"environment"—whatever environment is set up by the onResume hook—then that
makes async functions much safer and easier for programmers to reason about,
while only restricting their power slightly.)
--
Brent Royal-Gordon
Architechies
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution