RADS Logo

⚡ Async/Await

Asynchronous programming in RADS

Async Functions

Use async blast to declare async functions.

async.rads
import net;

async blast fetch_data(str url) -> str {
    turbo stream response = await net.http_get(url);
    return await response.text();
}

async blast main() {
    turbo str data = await fetch_data("https://api.example.com");
    echo(data);
}

Await Keyword

Use await to wait for async operations.

Spawn for Concurrency

Use spawn to run tasks concurrently.

spawn.rads
async blast task1() {
    echo("Task 1 running");
}

async blast task2() {
    echo("Task 2 running");
}

async blast main() {
    spawn task1();
    spawn task2();
    echo("Both tasks spawned");
}

Stream Type

The stream type represents async I/O streams.

Async Features

  • async blast - Async function declaration
  • await - Wait for async operation
  • spawn - Concurrent execution
  • stream - Async I/O type