-
Notifications
You must be signed in to change notification settings - Fork 149
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
Should smol::Timer
work inside a tokio
runtime?
#26
Comments
After doing some more digging it seems quite clear to me that Sorry for the noise! I'm doing these experiments with the aim of better learning how to write an async library, i.e. what aspects of each of these async crates are portable and what are not. The |
Only tokio has the concept of a runtime context, which you enter using In contrast to that, async-std and smol have a single global context, which means all timers and I/O handles are registered in some kind of global variable. When a timer is used, it will simply register itself in that global variable, whereas tokio's timer will access the thread-local to figure out where to register itself. Therefore, async-std's and smol's timers never panic because they're always and everywhere inside the runtime context. The difference between async-std and smol is in how the reactor (I/O and timers) is driven. In async-std there's a lazily initialized global executor thread pool that drives the reactor. As soon as you create a timer, or access the runtime in any way, it will be initialized and spin up the thread pool. So everything just works. Now, smol chose to not spin up a thread pool for you. Instead, you need to start at least one executor using You could just do |
Hi!
I'm currently experimenting by attempting to run futures created with
smol
in other async runtimes.In this case I'm having a go at writing to an
Async<UdpSocket>
once per second. I've noticed that writing to theAsync<UdpSocket>
does seem to work nicely. However, theTimer
future does not seem to make progress in thetokio
runtime. If I instead create my "once-per-second" stream usingfutures-timer
, everything seems to work as expected.Is this expected behaviour? I'm still quite new to async Rust so feel free to tell me if I'm being silly! Otherwise let me know if you'd like me to assemble a small test case and I'll put something together next time I get the chance.
Edit: I should note that I did try enabling the
"tokio02"
feature but it didn't seem to have an effect - I guess because this feature is aimed running tokio futures inside a smol runtime and not the other way around?Edit 2: I just tested with
async-std
instead oftokio
and in this case it seems thesmol::Timer
does work.The text was updated successfully, but these errors were encountered: