4 ms·
If one is using a function from tokio itself, is it not a reasonable expectation that one should check the docs as to whether the function requires the tokio ex
by davidatbu 4y ago
If one is using a function from tokio itself, is it not a reasonable expectation that one should check the docs as to whether the function requires the tokio executor?
- ahepp 4y agoPart of me agrees with what you’re saying. I mean, tokio is right there in the namespace. But another part of me questions why it’s ok that calling a function in the wrong context is a runtime panic rather than a compilation error. Coming from a C background it seems pretty normal to just have a “tokio_context*” argument on tokio functions that would at least make the statefullness less obscure?
- davidatbu 4y agoIs what you're suggesting that one has to pass that `tokio_context` into every `.await()`? If so, I personally would be in strong opposition, cuz I don't think the verbosity cost is justified, in any of the use cases for async I've come across.
- ahepp 4y agoI don't think you'd have to pass the context into an await? Await is a Rust construct, not a tokio one. Unless I'm making a complete fool of myself... Maybe I'm just jaded from writing too much C, but it doesn't seem like a big deal to me to change sleep(duration) to sleep(ctx, duration). Three letters to be correct, transparent, and not have global state? Look at what a complete mess the C standard library is from where they used global state like that. I'm sure there are lots of other ways you could do it, like make the context it's own struct and call a sleep impl for the struct or something?
- davidatbu 4y agoYeah, I guess we're disagreeing about a very non-concrete proposal, so there isn't much point to our convo :)
- lalaithion 4y agoHere's an example from outside the tokio library: https://github.com/google/tarpc/issues/297 https://github.com/google/tarpc/issues/297
- davidatbu 4y agoThanks! I guess it's more common than what my personal experience suggests (which is that it never happens).