-
Notifications
You must be signed in to change notification settings - Fork 88
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
shiny future: Barbara enjoys an async sandwich #174
shiny future: Barbara enjoys an async sandwich #174
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, esp. the hints about some of the ways it might be done. Thanks @seanmonstar!
Looks quite interested, a more flexible Just wondering, now the difference is that What if the user did not create any runtime but Maybe we could have a global |
This is a good question to highlight. What happens in this scenario? Perhaps also in a case where there are multiple runtimes. |
I imagined that calling
Could be an interesting separate story. There would be a lot of nuance to getting the implementation and decisions of that right. The original idea was that runtimes would all use |
Something like glibc runtime feature detection which is only done once and cached? See rust-lang/rust#68455 (comment) |
# ✨ Shiny future stories: Barbara enjoys her async-sync-async sandwich :sandwich: | ||
|
||
:::warning | ||
Alternative titles: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't certain about the title, so I listed some alternatives. Now a few days later, I still prefer the original, but I can change if desired. Otherwise, I can just nuke this part first.
|
||
impl PermitRequest for HasHeader { | ||
fn permit(&self, req: &Request) -> bool { | ||
task::block_on(req_has_header(req)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While a block_on
in std would already go a long way here, given how often this is needed, I wonder if we could do even better and provide a method on futures, so people can just use it like .await
:
req_has_header(req).block()
In fact, if it was up to me, I'd even want it as part of the language:
req_has_header(req).block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original Future
trait had a wait
method, which did exactly that. We chose to remove it, because it was too easy for people to reach for instead of just letting the future be chained with others (now I'd say just .await
). While I want to make it more forgiving in instances when a user has to do this, I'd still want to encourage users to try not to, since it is worse than using .await
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm.. wait
can very easily be confused with await
and I can see most programmers new to async, confusing them, but I see your point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I'm referring to Future
v0.1, which existed before there was async/await syntax. People would often do things like this because of how easy it was:
first_fut.and_then(|val| {
// a few lines of whatever
let foo = do_another_future(val).wait();
// and other lines
})
Rendered