Skip to content

hovsep/fmesh

Repository files navigation

f-mesh

f-mesh

Flow Based Programming inspired framework in Go

Learn more about FBP (originally discovered by @jpaulm) or read the documentation

What is it?

F-Mesh is a functions orchestrator inspired by FBP. It allows you to express your program as a mesh of interconnected components (or more formally as a computational graph).

Main concepts:

  • F-Mesh consists of Components - the main building blocks
  • Components have unlimited number of input and output Ports
  • Ports can be connected via Pipes
  • Ports and pipes are type agnostic, any data can be transferred to any port
  • The framework works in discrete time, not it wall time. The quant of time is 1 activation cycle, which gives you "logical parallelism" out of the box (activation function is running in "frozen time")
  • Learn more in documentation

What it is not?

F-mesh is not a classical FBP implementation, it does not support long-running components or wall-time events (like timers and tickers)

Example:

fm := fmesh.New("hello world").
	WithComponents(
		component.New("concat").
			WithInputs("i1", "i2").
			WithOutputs("res").
			WithActivationFunc(func(this *component.Component) error {
				word1 := this.InputByName("i1").FirstSignalPayloadOrDefault("").(string)
				word2 := this.InputByName("i2").FirstSignalPayloadOrDefault("").(string)
				this.OutputByName("res").PutSignals(signal.New(word1 + word2))
				return nil
			}),
		component.New("case").
			WithInputs("i1").
			WithOutputs("res").
			WithActivationFunc(func(this *component.Component) error {
				inputString := this.InputByName("i1").FirstSignalPayloadOrDefault("").(string)
				this.OutputByName("res").PutSignals(signal.New(strings.ToTitle(inputString)))
				return nil
			}))

fm.ComponentByName("concat").OutputByName("res").PipeTo(fm.ComponentByName("case").InputByName("i1"))

// Init inputs
fm.ComponentByName("concat").InputByName("i1").PutSignals(signal.New("hello "))
fm.ComponentByName("concat").InputByName("i2").PutSignals(signal.New("world !"))

// Run the mesh
_, err := fm.Run()

// Check for errors
if err != nil {
	fmt.Println("F-Mesh returned an error")
	os.Exit(1)
}

//Extract results
results := fm.ComponentByName("case").OutputByName("res").FirstSignalPayloadOrNil()
fmt.Printf("Result is : %v", results) // Result is : HELLO WORLD !

See more in examples directory.