Skip to content

linuxy/zoro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zoro

Coroutines for Zig based on minicoro

Architectures Supported

  • x86_64 (linux)
  • x86_64 (win) as a wrapper
  • x86_64 (mac)
  • ARM/ARM64 (any)

Features

  • Stackful Coroutines
  • Inside Threads
  • Nested Coroutines

An example

const std = @import("std");

const Zoro = @import("zoro").Zoro;

pub fn fibonacci(zoro: *Zoro) !void {
    var m: u64 = 1;
    var n: u64 = 1;
    var max: u64 = undefined;

    try zoro.pop(&max);
    while (true) {
        try zoro.push(&m);
        try zoro.yield();
        var tmp: u64 = m +% n;
        m = n;
        n = tmp;
        if (m >= max) break;
    }
    try zoro.push(&m);
}

pub fn main() !void {
    var zoro = try Zoro.create(fibonacci, 0);
    defer zoro.destroy();

    var max: u64 = 10000000000000000000;
    try zoro.push(&max);
    var counter: usize = 1;
    while (zoro.status() == .SUSPENDED) {
        try zoro.restart(); //resume

        var ret: u64 = 0;
        try zoro.pop(&ret);
        std.log.info("fib {} = {}", .{counter, ret});
        counter += 1;
    }
}

UB

Releases

No releases published

Packages

No packages published