5 ms·
It's too late to remove async fn, but can we still implement his "What if the alternative was nicer"? Is there any good reason why I can't use await in a non-
by bryanlarsen 3y ago
It's too late to remove async fn, but can we still implement his "What if the alternative was nicer"? Is there any good reason why I can't use await in a non-async function that returns a Future?
- convolvatron 3y agoI suspect there are enough performance differences and small semantic gotchas in functions that can be suspended and restarted without burning a kernel thread to make that undesirable.
- insanitybit 3y ago> It's too late to remove async fn, but can we still implement his "What if the alternative was nicer"? I think that "Ability to forgo naming an associated type name." seems very reasonable to me > Is there any good reason why I can't use await in a non-async function that returns a Future? You can do this afaik
- Buttons840 3y agoI think you have to use something like the "pollster" crate, which is an async runtime that just pauses the thread until the future is ready.
- insanitybit 3y ago`block_on` should do that, as should local task sets, but that's not necessary afaik - you can just poll it normally
- TrueDuality 3y agoI kind of wish the calling convention for async didn't have await at all. What if instead of a special syntax for waiting on an async function you instead had a special syntax for _not_ awaiting. If you want a copy of the future then there is an alternate syntax. What I really want is for my synchronous and asynchronous code to be a lot more transparent and not force my hand depending on whether I'm calling from a synchronous or asynchronous context. I know this is a really difficult ask because of the lack of knowledge of what runtime to use when calling an async task in the context of a synchronous call... Its the coloring problem I ultimately hate fighting against. There are definitely times that I care about it, long running blocking synchronous calls and getting a handle on a Future are really the only ones I can think of and they tend to be the exception not the norm.
- vacuity 3y agoVery fair, but if Rust gets a great effects system I think that'll be even better. Will take a while, though.
- epilys 3y agothe main problem is that there needs to be someone in charge of waking up your thread when it's ready, and also to run it. in your case you don't need the run part. But the waking part is tied to what the future is: a busy polling loop, a sleeping select, an io_uring; in fact it can be anything. You can manually make a future that returns immediately or sleeps forever. The rest of your code has no way to know these implementation details.