Is there a way to get the Context from wtihin an async fn

Hi So I want to call "poll_read" within an async fn, and if there was nothing to read yet then do something. So using await doesn't make sense.

I do want my function to be async, and not to write the outer future myself in terms of poll.

Is there a way to get the "Context" of the currently running async function, in order to use it to call "poll"?

You can use poll_fn from the futures crate: futures::future::poll_fn - Rust

That's pretty cool, rather than getting the context directly, you create a future that can get the context on next call.

The reason it must work like this is that you get a different contex every time the future is polled.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.