https://github.com/floscodes/futurez
A small runtime for running futures in zig.
https://github.com/floscodes/futurez
zig-package
Last synced: 24 days ago
JSON representation
A small runtime for running futures in zig.
- Host: GitHub
- URL: https://github.com/floscodes/futurez
- Owner: floscodes
- License: mit
- Created: 2025-06-08T13:29:00.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-05-28T10:19:48.000Z (29 days ago)
- Last Synced: 2026-05-28T12:13:03.844Z (29 days ago)
- Topics: zig-package
- Language: Zig
- Homepage:
- Size: 68.4 KB
- Stars: 9
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# futurez
[](https://github.com/floscodes/futurez/actions/workflows/ci.yml)
[](LICENSE)
futurez is a small runtime for running asynchronous tasks using futures in Zig.
## Minimal Example
```zig
const std = @import("std");
const futurez = @import("futurez");
const Runtime = futurez.Runtime;
fn main() !void {
const allocator = std.heap.page_allocator;
var rt = try Runtime.init(allocator);
defer rt.deinit();
const task = try rt.spawn(myTaskFunction, .{});
const result = task.join(i32);
std.debug.print("Result: {d}\n", .{result});
}
fn myTaskFunction() i32 {
return 42;
}
```
For a complete example showcasing advanced usage with dynamic allocations and multiple parameters, see [examples/basic.zig](./examples/basic.zig).
## Overview
futurez spawns as many worker threads as logical CPU cores available on your machine. These threads continuously pick up and run asynchronous tasks you spawn via `Runtime.spawn`. Finished tasks remain in the task queue until you call the `join()` method on the associated `*Task` to retrieve the result.
You can also control the number of worker threads by initializing the runtime with a specific core count using `initWithCores()`:
```zig
const allocator = std.heap.page_allocator;
var rt = try Runtime.initWithCores(allocator, 4);
defer rt.deinit();
```