Dz
Djazair
v1.0.5
🔍

Async / Await

Djazair supports coroutine-based concurrency using async fn and await.

Async Functions

Declare with async fn. They return a coroutine instead of executing immediately:

async fn fetchData()
    # Simulate async work
    return 42
end

let task = fetchData()
print(task)  # Coroutine object

Awaiting Results

Use await to block until the coroutine completes and get its return value:

let result = await task
print(result)  # => 42

Multiple Async Calls

Launch several coroutines and await them:

async fn getValue(n)
    return n * 2
end

let t1 = getValue(10)
let t2 = getValue(20)
let r1 = await t1
let r2 = await t2
print(r1 + r2)  # => 60

Async Methods in Classes

Async methods in classes do not use the fn keyword — just async directly:

class Fetcher
    async load(id)
        return "data_" + str(id)
    end
end

let f = Fetcher()
let result = await f.load(42)
print(result)  # => "data_42"

Note: Exceptions inside async coroutines propagate when awaited in the parent context.

© 2026 Harizi Riyadh. Released under the MIT License.
Official Website for Djazair.