Skip to content
Write StreamFunction in Zig

Implement StreamFunction in Zig (opens in a new tab)


This feature is currently in alpha and subject to change.

Install CLI

$ curl -fsSL "" | sh

Write a StreamFunction in Zig

const std = @import("std");

extern fn yomo_observe_datatag(tag: u32) void;
extern fn yomo_load_input(pointer: *const u8) void;
extern fn yomo_dump_output(tag: u32, pointer: *const u8, length: usize) void;

pub fn main() !void {"yomo wasm sfn on zig", .{});

export fn yomo_init() void {

export fn yomo_handler(input_length: usize) void {"wasm zig sfn received {d} bytes", .{input_length});

    // load input data
    const allocator = std.heap.page_allocator;
    const input = allocator.alloc(u8, input_length) catch undefined;

    // process app data
    const output = std.ascii.allocUpperString(allocator, input) catch undefined;

    // dump output data
    yomo_dump_output(0x34, &output[0], output.len);

Compile to WASI (opens in a new tab)

$ zig build-lib src/main.zig -target wasm32-wasi -dynamic --name sfn

Run Streaming Serverless Function

yomo run /path/to/sfn.wasm