https://github.com/ciathefed/coroutines-zig
Zig bindings for tsoding's coroutines library
https://github.com/ciathefed/coroutines-zig
coroutines zig zig-package
Last synced: about 1 month ago
JSON representation
Zig bindings for tsoding's coroutines library
- Host: GitHub
- URL: https://github.com/ciathefed/coroutines-zig
- Owner: ciathefed
- License: mit
- Created: 2025-03-09T23:15:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-12-03T01:21:57.000Z (7 months ago)
- Last Synced: 2025-12-06T01:56:25.270Z (7 months ago)
- Language: C
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# coroutines-zig
Zig bindings for tsoding's [coroutines](https://github.com/tsoding/coroutines) library
## Install
```shell
zig fetch --save "git+https://github.com/ciathefed/coroutines-zig#v0.1.0"
```
Add the following to `build.zig`:
```zig
const coroutines = b.dependency("coroutines", .{
.target = target,
.optimize = optimize,
});
exe_mod.addImport("coroutines", coroutines.module("coroutines"));
```
## Example
```zig
const std = @import("std");
const coroutines = @import("coroutines");
fn counter(arg: ?*anyopaque) callconv(.C) void {
const n = @as(usize, @intCast(@intFromPtr(arg)));
for (0..n) |i| {
std.debug.print("[{}] {}\n", .{ coroutines.id(), i });
coroutines.yield();
}
}
pub fn main() !void {
coroutines.init();
coroutines.go(counter, @ptrFromInt(5));
coroutines.go(counter, @ptrFromInt(10));
while (coroutines.alive() > 1) {
coroutines.yield();
}
}
```
You can find more examples [here](https://github.com/ciathefed/coroutines/tree/main/examples)