example/

directory
v1.16.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: Apache-2.0

README

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

  • 5-backflow: source can receive stream functions processed results.

    This feature is experimental.

Steps:
  1. 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), 
    )
    
  2. 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:
})

Directories

Path Synopsis
0-basic
sfn
3-multi-sfn
4-cascading-zipper
sfn
5-backflow
6-mesh
uppercase

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL