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(inputs *port.Collection, outputs *port.Collection) error {
					word1 := inputs.ByName("i1").FirstSignalPayloadOrDefault("").(string)
					word2 := inputs.ByName("i2").FirstSignalPayloadOrDefault("").(string)

					outputs.ByName("res").PutSignals(signal.New(word1 + word2))
					return nil
				}),
			component.New("case").
				WithInputs("i1").
				WithOutputs("res").
				WithActivationFunc(func(inputs *port.Collection, outputs *port.Collection) error {
					inputString := inputs.ByName("i1").FirstSignalPayloadOrDefault("").(string)

					outputs.ByName("res").PutSignals(signal.New(strings.ToTitle(inputString)))
					return nil
				})).
		WithConfig(fmesh.Config{
			ErrorHandlingStrategy: fmesh.StopOnFirstErrorOrPanic,
			CyclesLimit:           10,
		})

	fm.Components().ByName("concat").Outputs().ByName("res").PipeTo(
		fm.Components().ByName("case").Inputs().ByName("i1"),
	)

	// Init inputs
	fm.Components().ByName("concat").InputByName("i1").PutSignals(signal.New("hello "))
	fm.Components().ByName("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.Components().ByName("case").OutputByName("res").FirstSignalPayloadOrNil()
	fmt.Printf("Result is : %v", results)

See more in examples directory.

Version 0.1.0-Sugunia is already released!