yasync
Yet another async/await for Nim
Summary
| Latest Version | 0.1.0 |
|---|---|
| License | MIT |
| CI Status | Failing |
| Downloads | 0 |
| Last Indexed | 2026-07-21 05:26 |
Tags
Authors
- Yuriy Glukhov
Installation
nimble install yasync
choosenim install yasync
git clone https://github.com/yglukhov/yasync
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| yasync | ✓ | ✓ | ✓ | - | - | - | - | - | - | - |
Dependencies
| Package | Version | Optional |
|---|---|---|
| nim >= | 2.2 | No |
Source
| Repository | https://github.com/yglukhov/yasync |
|---|---|
| Homepage | https://github.com/yglukhov/yasync |
| Registry Source | nimble_official |
README
yasync - Yet another async/await for Nim
Requires nim devel or 2.0.
- Semantics is very close to that of Nim's std
async,awaitandFuture[T]. awaitoperation doesn't cause any heap allocations (except async closures, and (mutually) recursive async calls).callSoonis not used and async code is guaranteed to run atomically betweenawaits across call boundaries (TODO: maybe add an example)- Function return type is written as
T, thenasynctransforms it toFuture[T]implicitly. - Supports cancellation of async tasks, with optional cancellation callbacks in terminal futures. Example.
- Provides optional compatibility layer for interop with existing
asyncdispatchandchronoscode. Example. The library itself is completely dispatcher agnostic, and doesn't depend on neitherasyncdispatch, norchronos.
This library introduces async, await and Future[T] similar in semantics to Nim's native ones, but implements an optimization to avoid heap allocations. Consider the following sample:
proc sleep(ms: int): Future[void] = ... # Let's assume this function doesn't allocate
proc foo(a: int): int {.async.} =
await sleep(a)
var b = a + 1
return b
proc bar() {.async.} =
let a = await foo(5)
let b = await foo(6)
echo a + b
waitFor bar()
If we pretend that sleep doesn't allocate, the whole waitFor operation above will not do a single allocation. The optimization happens in async functions on await calls.
TODO: Describe how it works in details
TODO: - [ ] Nice stack traces