3 ms·
It's probably too complicated to explain in a HN comment, but I don't understand why not having Leak forces futures to be 'static.
by jenadine 3y ago
It's probably too complicated to explain in a HN comment, but I don't understand why not having Leak forces futures to be 'static.
- pornel 3y agoThere's a desire to have futures that run on other threads, but can borrow from temporary locations like stack of their caller. This can't be implemented robustly, because there's no way to enforce the outer scope (the one lending its stack) won't return while the futures are still running. It needs a blocking mechanism that does "wait, your async code hasn't finished yet!", but implementing that via guards and destructors can be bypassed by leaking them. https://without.boats/blog/the-scoped-task-trilemma/ https://without.boats/blog/the-scoped-task-trilemma/ ---- However, running futures on the same thread, with a simple plain .await, does allow them to borrow from the caller's stack safely without restriction. So the first poster in this thread may be doing something unusual, perhaps just over-using multi-threaded spawn() where join_all or streams would suffice.