Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the future output #5

Open
lastmjs opened this issue Aug 9, 2021 · 1 comment
Open

Return the future output #5

lastmjs opened this issue Aug 9, 2021 · 1 comment

Comments

@lastmjs
Copy link

lastmjs commented Aug 9, 2021

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?

@TTTiNNNy
Copy link
Contributor

TTTiNNNy commented Oct 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants