You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Detect blocking I/O in async: it seems the best we can do for now is to document the issues.
A "blocking-in-async" lint in clippy or rustc would be much nicer, if feasible, but would occur upstream...someday.
Miscellaneous small TODOs (tagged as TODO.async) throughout code.
Response bodies are passed back to hyper using a channel.
The async APIs are based on rust's async/await feature and std::future::Future, running on the tokio (0.2) runtime.
High-level APIs (routes and catchers):
Routes can now be defined as #[get|post|route(...)] async fn(params...) -> R where R is any Responder type. Routes that do not await anything can remain unchanged. #[catch]ers can also be defined as an async fn.
Methods on Data now return Futures that must be .awaited. As a consequence, any route that uses Data directly must be async. Routes that use data guards such as Json are not affected by this change.
Routes that make their own network requests or other I/O should be async, as it will allow other requests to continue while waiting for the operation.
Mid and low-level APIs (FromTransformedData and FromData, Fairing, Responder)
Several traits are now defined using async-trait, re-exported as #[rocket::async_trait].
Data is read asynchronously: DataStream implements tokio::io::AsyncRead instead of Read. Thus, FromTransformedData::transform and From(Transformed)Data::from_data are async fn or return Futures.
Response bodies are streamed to the client asynchronously: set_body and related methods expect tokio::io::AsyncRead instead of Read.
Consequently, Fairing::on_response and Responder::respond_to are now async fn. This allows Responders and Fairings to access and/or replace the body data.
The testing APIs have been moved to rocket::local::asynchronous and rocket::local::blocking. The blocking test API is simpler to use, and recommended when possible.
#[rocket::main], #[rocket::launch], and #[rocket::async_test] have been added to make async fn easily accessible for main() and test().
Many long-standing bugs with keep-alive, graceful shutdown (Clean shutdown? #180), performance, and more are fixed or will be easier to fix by using actively-supported versions of libraries.
Some new functionality will be possible to implement, such as SSE and WebSockets. These will likely not make it into Rocket 0.5. At this point, Rocket should not be missing any APIs necessary to implement SSE "by hand". WebSockets is a bit more complicated, and tracked in Native WebSocket support #90 .
Status
Rocket's
masterbranch is currently fully asynchronous and supports async/await!Pending
A "blocking-in-async" lint in
clippyorrustcwould be much nicer, if feasible, but would occur upstream...someday.TODO.async) throughout code.Done
AsyncReadvsStream<Item=Result<Chunk, Error>>Design
The
asyncAPIs are based on rust's async/await feature andstd::future::Future, running on thetokio(0.2) runtime.#[get|post|route(...)] async fn(params...) -> RwhereRis anyRespondertype. Routes that do notawaitanything can remain unchanged.#[catch]ers can also be defined as anasync fn.Datanow returnFutures that must be.awaited. As a consequence, any route that usesDatadirectly must beasync. Routes that use data guards such asJsonare not affected by this change.async, as it will allow other requests to continue while waiting for the operation.FromTransformedDataandFromData,Fairing,Responder)async-trait, re-exported as#[rocket::async_trait].DataStreamimplementstokio::io::AsyncReadinstead ofRead. Thus,FromTransformedData::transformandFrom(Transformed)Data::from_dataareasync fnor returnFutures.set_bodyand related methods expecttokio::io::AsyncReadinstead ofRead.Fairing::on_responseandResponder::respond_toare nowasync fn. This allows Responders and Fairings to access and/or replace the body data.rocket::local::asynchronousandrocket::local::blocking. Theblockingtest API is simpler to use, and recommended when possible.#[rocket::main],#[rocket::launch], and#[rocket::async_test]have been added to makeasync fneasily accessible formain()andtest().