Flow based programming in elixir

metaprogramming
flow

#1

I want to know if we can implement flow based programming using a graph. Where each node is a process by itself, and the graph can be dynamic in nature. I’m not sure how I can achieve this in elixir. Please let me know your thoughts.


#2

If you use Supervision tree you have - you guessed it, tree. Maybe that’s a partial solution?


#3

The quick answer is yes. How would you use this graph flow based programming ?


#4

@tty, I basically want to create REST API’s using the graphs.


#5

Take a look at the flow library. It might provide the tools you are looking for :slight_smile:.


#6

flow isn’t related to the FBP paradigm


#7

I still don’t quite get it. Are you intending each graph node as a state ? The edges as transitions to that state ?


#8

I want to create something like this

Each node being a function


#9

Yes that looks very possible. If each node is a function you have the choice of having an Elixir process handle one function or you can mimic all of these within a FSM. Unfortunately Elixir doesn’t have a corresponding Erlang gen_fsm / gen_statem and will have to use the Erlang behaviours.


#10

I think state machines aren’t the answer to this. As we might me dealing with a function which requires more than one input argument, and they are waiting for the output from a different node, which can be of asynchronous nature.


#11

Ok. Go with GenServer to begin with and model a simple system. It looks very doable.


#12

There is an Elixir wrapper for gen_statem here…

https://hexdocs.pm/gen_state_machine/GenStateMachine.html


#13

Here’s a FBP library:


#14

Take a look at this talk about the topic


#15

What you are looking for is https://github.com/antonmi/flowex which mixes FBP and ROP, I’m personalize working on my own library called conveyer based on the following libraries:


#16

I was exploring ‘ElixirFBP’ and is the closest to what I am looking for, thanks for finding the alternatives.


#17

Here’s another relatively new library implementing FBP and is based on GenStage: https://github.com/suitepad-gmbh/pipette


#18

I wrote about Elixir and FBP in a blog at the time that GenStage and Flow were announced.


#20

Hi, I’ve created a proof-of-concept implementation.

Please have a look and let me know your views.
Any suggestions or contributions are welcome.

This is inspired by @pcmarks implementation.


#21

Hi Sarat,

I apologize for not getting back to you sooner - been very busy. I will take a look at your work in a few days.

Best,

Peter