Skip to main content

2 posts tagged with "rust"

View All Tags

JavaScript developers may feel at home with Rust's concurrency model, which uses the async/await concept. In JavaScript we have Promise to represent eventual results of async operations, and in Rust we have Future.

The following shows an example of async and await syntax in JavaScript and Rust code:

JavaScript

greet.js
async function main() {  await greet("Hi there!");}
async function greet(message) {  console.log(message);}
/*Output:
Hi there!*/

Rust

greet.rs
#[tokio::main]async fn main() {    greet("Hi there!").await;}
async fn greet(message: &str) {    println!("{}", message);}
/*Output:
Hi there!*/

Currently, Rust does not include an async runtime out-of-the-box. We use the Tokio runtime in our examples.