-
Notifications
You must be signed in to change notification settings - Fork 3
Concurrency
Important
This page is under development. The concurrency model is being designed. Full documentation will be added once the design is finalized.
Kairo's concurrency system provides async/await, coroutines, and thread-level primitives. The following features are planned and referenced across the existing documentation:
The async modifier on functions and the await keyword for waiting on asynchronous results.
See Functions for the async modifier.
Functions with a yield T return type produce values cooperatively. The yield keyword suspends
the function and produces a value to the caller. See
Functions for yield return types.
Launching concurrent work. Syntax and runtime model (green threads, OS threads, or event loop) are being finalized.
Thread-safe wrapper type for lock-free operations. Referenced in Functions.
Per-thread storage modifier. Referenced in Functions.
Mutexes, channels, and other coordination mechanisms will be documented here once the standard library concurrency API is finalized.
Classes can define fn <T> op await(self, obj: std::forward<T>) -> T to customize the behavior of
await when called on an instance. See
Operators for the op await overload.
await async_fn() // syntax sugar for a state machine
spawn some_async_fn() // syntax sugar for detaching a thread
yield some_value // syntax sugar for a coroutine, function must have yield on return type
fn get_tokens() -> yield string {
yield "token1"
yield "token2"
}
op await is overloadable: fn op await (self) -> T for custom async types.
-
await async_fn()syntax sugar for state machine -
spawn some_async_fn()syntax sugar for detaching a thread -
yield some_valuecoroutine syntax, function must have-> yield Treturn type -
fn op await (self) -> Toverloadable for custom async types -
atomic Tthread-safe wrapper type -
thread Tthread-local storage type
This wiki mirrors the language reference at kairolang.org/docs. To edit a page, edit the source at kairo-web/src/content/docs/language changes sync automatically.
Start here: Primitives
1. Fundamentals
2. Functions & Control Flow
3. Types
4. Modules & Metaprogramming
5. Memory & Safety
6. Interop & Concurrency