You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Task::local no longer exists, and LocalExecutor requires some setup in order to use. Please consider providing an example (or a pointer to a crate implementing an appropriate pattern) for how to keep a set of local executors around for running non-Send futures, concurrently with the set of normal executors.
The text was updated successfully, but these errors were encountered:
If you want a similar API to v0.1, you can use a helper something like this:
use async_executor::LocalExecutor;let local_ex = LocalExecutor::new();
helper::run_local(async{let task = helper::spawn_local(async{1 + 2});assert_eq!(task.await,3);});mod helper {use async_executor::{LocalExecutor,Task};use scoped_tls::scoped_thread_local;scoped_thread_local!(staticLOCAL_EX:LocalExecutor);pubfnrun_local<T>(local_ex:&LocalExecutor,future:impl std::future::Future<Output = T>) -> T{LOCAL_EX.set(local_ex, || {
futures_lite::future::block_on(local_ex.run(f))})}pubfnspawn_local<T>(future:impl std::future::Future<Output = T>) -> Task<T>{ifLOCAL_EX.is_set(){LOCAL_EX.with(|local_ex| local_ex.spawn(future))}else{panic!("`spawn_local()` must be called from a `LocalExecutor`")}}}
Note that in 0.1 LocalExecutor::run + Task::local and similar API like above, you can easily write code like can cause a deadlock due to recursive block-on.
Task::local
no longer exists, andLocalExecutor
requires some setup in order to use. Please consider providing an example (or a pointer to a crate implementing an appropriate pattern) for how to keep a set of local executors around for running non-Send futures, concurrently with the set of normal executors.The text was updated successfully, but these errors were encountered: