executor icon indicating copy to clipboard operation
executor copied to clipboard

Return the future output

Open lastmjs opened this issue 4 years ago • 1 comments

I would love to use this little function like I have been using tokio::runtime::Runtime::new().unwrap().block_on, which will return the result of the future so that I can easily move on with the value returned.

I am not sure how to achieve that with executor. I've been declaring a variable outside of the future closure and trying to mutate it from within the closure, so that I can use the value once the future has completed. It's not working out so well. What can be done?

lastmjs avatar Aug 09 '21 17:08 lastmjs

Hi, I think there are several features, that don't let as use something stuff like that. At first, (and at general) executor can work at no_std context, so we cant use blocking sleep features, like std::thread::sleep, std::sync::Mutex(with thread sleep feature. Note, that this executor use spin::mutex mutex, that has some flaws, bot work at no_std context), std::sync::Condvar and etc. So, second, if this features will be realized, it will block current thread(with 100% CPU core load) until Task done. At std context I suggest using local variables and closures, like you try before, but wrapped at Arc::Mutex<<T>> type. Otherwise we should found something like that or use(or create) other synchronization primitives like implemented at this embedded executor https://github.com/embassy-rs/embassy/tree/main/embassy-sync

TTTiNNNy avatar Oct 03 '23 14:10 TTTiNNNy