Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

How to call an async function from a normal function? #43

Closed
ufosky opened this issue May 31, 2019 · 3 comments
Closed

How to call an async function from a normal function? #43

ufosky opened this issue May 31, 2019 · 3 comments

Comments

@ufosky
Copy link

ufosky commented May 31, 2019

I found if I use an async function, the other codes using this function must implement as an async function. Is there some suggestion for using async function from normal function?

@zeroqn
Copy link

zeroqn commented Jun 6, 2019

Either use

futures::executor::block_on(your_future)

or

use runtime_tokio::Tokio;

fn main() {
    runtime::raw::enter(Tokio, your_future);
}

If you want to run it using this crate.

@yoshuawuyts
Copy link
Collaborator

yoshuawuyts commented Jun 6, 2019

We could / should probably expose some convenience methods here, so nobody ever needs to use runtime::raw directly:

with #[runtime::main]

runtime::task::block_on(async move {
    /* code goes here */
})

without #[runtime::main]

runtime_tokio::Tokio::block_on(async move {
    /* code goes here */
})

@yoshuawuyts
Copy link
Collaborator

Related: #42

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants