3 ms·
> async runtimes cannot use this feature to provide borrowing across tasks They can't use this function, but with some duplicated unsafe code they can still pr
by oconnor663 4y ago
> async runtimes cannot use this feature to provide borrowing across tasks
They can't use this function, but with some duplicated unsafe code they can still provide similar APIs for their callers, right? Things like this: https://github.com/jaboatman/tokio-scoped https://github.com/jaboatman/tokio-scoped
- thramp 4y agothe problem with this approaches like these that it requires blocking the runtime: https://github.com/jaboatman/tokio-scoped/blob/master/src/lib.rs#L229-L231 https://github.com/jaboatman/tokio-scoped/blob/master/src/li....
- klabb3 4y agoI just checked quickly so may be wrong, but it looks like they're pulling the same trick as with the new scoped threads, ie only lexical scoping. Note also that the scope function is blocking and called from within an async fn, which is normally not great for composability with other async code. That said, taking a step back it has crossed my mind that bringing back true scoping with unsafe in the impl might be an acceptable way forward, despite how upsetting this is to a lot of rustaceans. I think that the failure modes (ie triggering UB) for this case can be simply enumerated in a short list of "DON'Ts" (such as putting a scoped join handle in an Arc). OTOH, since leaking was formalized and explicitly allowed (heck, even borderline encouraged through mem::forget), god knows if people have exploited that for other cases in true Hyrum's law fashion, that breaks the abovementioned idea. They certainly had the right to.