mirror of https://github.com/stjepang/smol
Fix compilation errors
This commit is contained in:
parent
890226254f
commit
f5805c87b8
|
@ -19,6 +19,7 @@ use async_net::TcpListener;
|
|||
use blocking::block_on;
|
||||
use futures::prelude::*;
|
||||
use http_types::{Request, Response, StatusCode};
|
||||
use smol::Task;
|
||||
|
||||
/// Serves a request and returns a response.
|
||||
async fn serve(req: Request) -> http_types::Result<Response> {
|
||||
|
@ -48,7 +49,7 @@ async fn listen(listener: TcpListener, tls: Option<TlsAcceptor>) -> Result<()> {
|
|||
let task = match &tls {
|
||||
None => {
|
||||
let stream = async_dup::Arc::new(stream);
|
||||
smol::spawn(async move {
|
||||
Task::spawn(async move {
|
||||
if let Err(err) = async_h1::accept(&host, stream, serve).await {
|
||||
println!("Connection error: {:#?}", err);
|
||||
}
|
||||
|
@ -59,7 +60,7 @@ async fn listen(listener: TcpListener, tls: Option<TlsAcceptor>) -> Result<()> {
|
|||
match tls.accept(stream).await {
|
||||
Ok(stream) => {
|
||||
let stream = async_dup::Arc::new(async_dup::Mutex::new(stream));
|
||||
smol::spawn(async move {
|
||||
Task::spawn(async move {
|
||||
if let Err(err) = async_h1::accept(&host, stream, serve).await {
|
||||
println!("Connection error: {:#?}", err);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ use async_net::{TcpListener, TcpStream};
|
|||
use blocking::block_on;
|
||||
use futures::io::{self, BufReader};
|
||||
use futures::prelude::*;
|
||||
use smol::Task;
|
||||
|
||||
/// An event on the chat server.
|
||||
enum Event {
|
||||
|
@ -88,7 +89,7 @@ fn main() -> io::Result<()> {
|
|||
|
||||
// Spawn a background task that dispatches events to clients.
|
||||
let (sender, receiver) = bounded(100);
|
||||
smol::spawn(dispatch(receiver)).detach();
|
||||
Task::spawn(dispatch(receiver)).detach();
|
||||
|
||||
loop {
|
||||
// Accept the next connection.
|
||||
|
@ -97,7 +98,7 @@ fn main() -> io::Result<()> {
|
|||
let sender = sender.clone();
|
||||
|
||||
// Spawn a background task reading messages from the client.
|
||||
smol::spawn(async move {
|
||||
Task::spawn(async move {
|
||||
// Client starts with a `Join` event.
|
||||
let _ = sender.send(Event::Join(addr, client.clone())).await;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ use blocking::block_on;
|
|||
use futures::prelude::*;
|
||||
use http::Uri;
|
||||
use hyper::{Body, Client, Request, Response};
|
||||
use smol::Task;
|
||||
|
||||
/// Sends a request and fetches the response.
|
||||
async fn fetch(req: Request<Body>) -> Result<Response<Body>> {
|
||||
|
@ -57,7 +58,7 @@ struct SmolExecutor;
|
|||
|
||||
impl<F: Future + Send + 'static> hyper::rt::Executor<F> for SmolExecutor {
|
||||
fn execute(&self, fut: F) {
|
||||
smol::spawn(async { drop(fut.await) }).detach();
|
||||
Task::spawn(async { drop(fut.await) }).detach();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ use blocking::block_on;
|
|||
use futures::prelude::*;
|
||||
use hyper::service::{make_service_fn, service_fn};
|
||||
use hyper::{Body, Request, Response, Server};
|
||||
use smol::Task;
|
||||
|
||||
/// Serves a request and returns a response.
|
||||
async fn serve(req: Request<Body>, host: String) -> Result<Response<Body>> {
|
||||
|
@ -73,7 +74,7 @@ struct SmolExecutor;
|
|||
|
||||
impl<F: Future + Send + 'static> hyper::rt::Executor<F> for SmolExecutor {
|
||||
fn execute(&self, fut: F) {
|
||||
smol::spawn(async { drop(fut.await) }).detach();
|
||||
Task::spawn(async { drop(fut.await) }).detach();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ use async_native_tls::{Identity, TlsAcceptor};
|
|||
use async_net::{TcpListener, TcpStream};
|
||||
use blocking::block_on;
|
||||
use futures::prelude::*;
|
||||
use smol::Task;
|
||||
|
||||
const RESPONSE: &[u8] = br#"
|
||||
HTTP/1.1 200 OK
|
||||
|
@ -65,7 +66,7 @@ async fn listen(listener: TcpListener, tls: Option<TlsAcceptor>) -> Result<()> {
|
|||
let tls = tls.clone();
|
||||
|
||||
// Spawn a background task serving this connection.
|
||||
smol::spawn(async move {
|
||||
Task::spawn(async move {
|
||||
if let Err(err) = serve(stream, tls).await {
|
||||
println!("Connection error: {:#?}", err);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
use async_net::{TcpListener, TcpStream};
|
||||
use blocking::block_on;
|
||||
use futures::io;
|
||||
use smol::Task;
|
||||
|
||||
/// Echoes messages from the client back to it.
|
||||
async fn echo(mut stream: TcpStream) -> io::Result<()> {
|
||||
|
@ -35,7 +36,7 @@ fn main() -> io::Result<()> {
|
|||
println!("Accepted client: {}", peer_addr);
|
||||
|
||||
// Spawn a task that echoes messages from the client back to it.
|
||||
smol::spawn(echo(stream)).detach();
|
||||
Task::spawn(echo(stream)).detach();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ use async_native_tls::{Identity, TlsAcceptor, TlsStream};
|
|||
use async_net::{TcpListener, TcpStream};
|
||||
use blocking::block_on;
|
||||
use futures::io;
|
||||
use smol::Task;
|
||||
|
||||
/// Echoes messages from the client back to it.
|
||||
async fn echo(stream: TlsStream<TcpStream>) -> Result<()> {
|
||||
|
@ -43,7 +44,7 @@ fn main() -> Result<()> {
|
|||
println!("Accepted client: {}", stream.get_ref().peer_addr()?);
|
||||
|
||||
// Spawn a task that echoes messages from the client back to it.
|
||||
smol::spawn(echo(stream)).detach();
|
||||
Task::spawn(echo(stream)).detach();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use anyhow::Result;
|
|||
use async_channel::{bounded, Sender};
|
||||
use blocking::block_on;
|
||||
use scraper::{Html, Selector};
|
||||
use smol::Task;
|
||||
|
||||
const ROOT: &str = "https://www.rust-lang.org";
|
||||
|
||||
|
@ -53,7 +54,7 @@ fn main() -> Result<()> {
|
|||
Some(url) => {
|
||||
println!("{}", url);
|
||||
tasks += 1;
|
||||
smol::spawn(fetch(url, s.clone())).detach();
|
||||
Task::spawn(fetch(url, s.clone())).detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ use async_net::{TcpListener, TcpStream};
|
|||
use async_tungstenite::WebSocketStream;
|
||||
use blocking::block_on;
|
||||
use futures::prelude::*;
|
||||
use smol::Task;
|
||||
use tungstenite::Message;
|
||||
|
||||
/// Echoes messages from the client back to it.
|
||||
|
@ -46,13 +47,13 @@ async fn listen(listener: TcpListener, tls: Option<TlsAcceptor>) -> Result<()> {
|
|||
match &tls {
|
||||
None => {
|
||||
let stream = WsStream::Plain(async_tungstenite::accept_async(stream).await?);
|
||||
smol::spawn(echo(stream)).detach();
|
||||
Task::spawn(echo(stream)).detach();
|
||||
}
|
||||
Some(tls) => {
|
||||
// In case of WSS, establish a secure TLS connection first.
|
||||
let stream = tls.accept(stream).await?;
|
||||
let stream = WsStream::Tls(async_tungstenite::accept_async(stream).await?);
|
||||
smol::spawn(echo(stream)).detach();
|
||||
Task::spawn(echo(stream)).detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue