Skip to content
Write StreamFunction in C

Implement StreamFunction in C


This feature is currently in alpha and subject to change.

Install CLI

$ curl -fsSL "" | sh

Write a StreamFunction in C

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
               import_name("yomo_observe_datatag"))) extern void
observe(uint32_t tag);
               import_name("yomo_context_tag"))) extern uint32_t
               import_name("yomo_context_data_size"))) extern size_t
               import_name("yomo_context_data"))) extern size_t
load_input(char *pointer, size_t length);
__attribute__((import_module("env"), import_name("yomo_write"))) extern int32_t
dump_output(uint32_t tag, const char *pointer, size_t length);
uint32_t yomo_init() {
  printf("wasm c sfn init\n");
  return 0;
void yomo_observe_datatags() { observe(0x33); }
void yomo_handler() {
  // load input tag & data
  uint32_t tag = get_tag();
  size_t length = get_input_size();
  char *input = malloc(length);
  load_input(input, length);
  printf("wasm c sfn received %zu bytes with tag[%#x]\n", length, tag);
  // process app data
  char *output = malloc(length);
  for (size_t i = 0; i < length; i++) {
    output[i] = toupper(input[i]);
  // dump output data
  dump_output(0x34, output, length);

Compile to WASI (opens in a new tab)

# download wasi-sdk from,
# and specify wasi-sdk version and path
$ export WASI_VERSION_FULL=20.0
$ export WASI_SDK_PATH=~/Downloads/wasi-sdk-$WASI_VERSION_FULL
$ $WASI_SDK_PATH/bin/clang --target=wasm32-wasi \
    --sysroot=$WASI_SDK_PATH/share/wasi-sysroot \
    -nostartfiles -fvisibility=hidden -O3 \
    -Wl,--no-entry,--export=yomo_init,--export=yomo_handler,--export=yomo_observe_datatags \
    -o sfn.wasm sfn.c

Run Streaming Serverless Function

yomo run /path/to/sfn.wasm