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");
const allocator = std.heap.page_allocator;

extern fn yomo_observe_datatag(tag: u32) void;
extern fn yomo_context_tag() u32;
extern fn yomo_context_data(pointer: *const u8, size: u32) u32;
extern fn yomo_context_data_size() u32;
extern fn yomo_write(tag: u32, pointer: *const u8, length: usize) u32;

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

export fn yomo_init() u32 {"wasm zig sfn init", .{});
    return 0;

export fn yomo_observe_datatags() void {

export fn yomo_handler() void {
    // load input data
    const tag = yomo_context_tag();
    const size: u32 = yomo_context_data_size();
    const input = allocator.alloc(u8, size) catch undefined;
    _ = yomo_context_data(&input[0], size);
    defer;"wasm zig sfn received {d} bytes with 0x{x}", .{ input.len, tag });

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

    // dump output data
    _ = yomo_write(0x34, &output[0], output.len);

Compile to WASI (opens in a new tab)

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

Run Streaming Serverless Function

yomo run /path/to/sfn.wasm