diff --git a/README.md b/README.md index cb35057..f22abd0 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,77 @@

f-mesh

Flow Based Programming inspired framework in Go

Learn more about FBP (originally discovered by @jpaulm)

- +

What is it?

+

F-Mesh is a simplistic FBP-inspired framework in Go. +It allows you to express your program as a mesh of interconnected components.

+

Main concepts:

+ + +

What it is not?

+

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

+

The framework is not suitable for implementing complex concurrent systems

+ +

Example:

+
+	// Create f-mesh
+	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").Signals().FirstPayload().(string)
+					word2 := inputs.ByName("i2").Signals().FirstPayload().(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").Signals().FirstPayload().(string)
+
+					outputs.ByName("res").PutSignals(signal.New(strings.ToTitle(inputString)))
+					return nil
+				})).
+		WithErrorHandlingStrategy(fmesh.StopOnFirstErrorOrPanic)
+
+	fm.Components().ByName("concat").Outputs().ByName("res").PipeTo(
+		fm.Components().ByName("case").Inputs().ByName("i1"),
+	)
+
+	// Init inputs
+	fm.Components().ByName("concat").Inputs().ByName("i1").PutSignals(signal.New("hello "))
+	fm.Components().ByName("concat").Inputs().ByName("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").Outputs().ByName("res").Signals().FirstPayload()
+	fmt.Printf("Result is :%v", results)
+
+ +

Version 0.1.0 coming soon

\ No newline at end of file