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

How can I use runtime in main without async #51

Closed
SephVelut opened this issue Jun 18, 2019 · 2 comments
Closed

How can I use runtime in main without async #51

SephVelut opened this issue Jun 18, 2019 · 2 comments

Comments

@SephVelut
Copy link

SephVelut commented Jun 18, 2019

// Cargo.toml
// [dependencies]
// runtime = { version = "0.3.0-alpha.5", feature = ["native"] }
// futures-preview = "0.3.0-alpha.16"

#![feature(async_await)]
use futures::prelude::*;
use runtime::net::TcpListener;
use futures::executor::block_on;

async fn listener() -> std::io::Result<()> {
    let mut listener = TcpListener::bind("127.0.0.1:8080")?;

    let mut sockets = listener.incoming();
    while let Some(socket) = sockets.next().await {
        match socket {
            Ok(s) => {
                runtime::spawn(async move {
                    let (reader, writer) = &mut s.split();
                    reader.copy_into(writer).await?;

                    Ok::<(), std::io::Error>(())
                }).await?;
            },
            Err(_) => (),
        }
    }

    Ok::<(), std::io::Error>(())
}

fn main() {
    block_on(listener());
}

thread 'main' panicked at 'the runtime has not been set', src/libcore/option.rs:1034:5

@sdroege
Copy link

sdroege commented Jun 18, 2019

Related to #42 . There's currently no API to explicitly run a runtime.

@SephVelut
Copy link
Author

Ah okay thank you

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

2 participants