Examples
Prerequisite
Install Task
Install Task
Install YoMo CLI
$ task -t ../Taskfile.yml cli:install
All examples can be run by Task, following the Install Task, execute task -l
in this directory will list all the examples.
$ task -l |grep example
* example-backflow: Backflow usage
* example-basic: YoMo basic usage
* example-cascading-zipper: Cascading zippers
* example-iopipe: IO Pipe
* example-multi-sfn: Multiple stream functions
* example-pipeline: Unix pipeline to cloud
* example-mesh: Edge mesh
* example-wasm: YoMo Stream Function using WebAssembly
* example-deno: YoMo Stream Function using Deno
* example-cli: Use the CLI to run stream functions
can run each example directly by task example-basic
, task example-cascading-zipper
and etc.
Basic example
- 0-basic: process the streams from IoT sound sensor.
Linux Pipeline over cloud
Multiple stream functions
- 3-multi-sfn: use 3 stream functions to process the streams in different cases.
- stream-fn-1: calculate the sound value in real-time.
- stream-fn-2: print the warning message when the sound value reaches a threshold.
- stream-fn-3: calculate the average value in a sliding window.
Cascading zippers
Backflow
Steps:
-
Set observe data tags on source:
source := yomo.NewSource(
"yomo-source",
"127.0.0.1:9000",
// set observe data tags, 0x34, 0x35 is sfn return data tags
yomo.WithObserveDataTags(0x34, 0x35),
)
-
Set receive handler on source
// set receive handler
source.SetReceiveHandler(func(tag byte, data []byte) {
logger.Printf("[source] ♻️ receive backflow: tag=%#v, data=%s", tag, data)
// TODO:
})