Hackernoon logoRust Async Libraries Cheat Sheet for Node.js Developers by@grantminer

Rust Async Libraries Cheat Sheet for Node.js Developers

image

Mio is a bit like libuv and libev before that. Itโ€™s a lightweight IO library over the OS abstractions.

Futures are basically the same as promises. Java and C# also call them Futures. The futures library also provides streams, which are similar to Node streams but more strongly typed. Streams are to futures as arrays are to values. Streams can even be viewed as a Future using into_future, where the resolved value is the next item in the stream along with the rest of the stream. This seems like a really neat feature.

Tokio-core depends on / is built on top of Futures and Mio. This library provides the I/O primitives and event loop for async I/O in Rust. Itโ€™s the connection between futures and mio. For example, connecting a TCP stream returns a Future resolving to a TCP stream, and a TCP listener implements a stream of TCP streams (accepted connections).

Reactor::Core is an instance of an event loop (like that of which you get implicitly in JavaScript). Reactor seems to be a commonly used name for an event loop type object.

Timeout is like setTimeout and interval is like setInterval.

Those are the basics, so the examples should be fairly self-explanatory. Here is another good read on Tokio.

a fast base64 encoder and decoder.

Hacker Noon is how hackers start their afternoons. Weโ€™re a part of the @AMIfamily. We are now accepting submissions and happy to discuss advertising &sponsorship opportunities.
To learn more, read our about page, like/message us on Facebook, or simply, tweet/DM @HackerNoon.
If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories. Until next time, donโ€™t take the realities of the world for granted!

Tags

Join Hacker Noon

Create your free account to unlock your custom reading experience.