sonntam / node-red-contrib-xstate-machine

A xstate-based state machine implementation using state-machine-cat visualization for node red.
MIT License
22 stars 8 forks source link

multi instance for every message #8

Open francescoagati opened 3 years ago

francescoagati commented 3 years ago

hello, the actual implmentation can support many instances of the same state machine. my idea is of passing the state and the data for every message and in this mode i can expose the state machine via an api rest and each session user have is state and data but the same implmentation of the state machine

sonntam commented 3 years ago

Thank you for the message.

Did I understand correctly that you

  1. manually want to input a current state, context and events,
  2. which in turn triggers an update of the state machine
  3. output the new state and context

i.e. the state machine node itself should not own any state information and it is fed externally into it instead? I think of it as some sort of "stateless state-machine".

I think this is a good idea and it could be done rather easily (except maybe the sidebar-part). I would probably create a new second node type for this.

Some caveats:

Another possible implementation could be that state-machine nodes themselves have functionality for multiple sessions, i.e. for every session the internal context is kept separately. A new session could be started/reset/deleted with special input messages.

What would suit you best for your use-case?

francescoagati commented 3 years ago

yes, i think that the stateless state-machine resolve all my problems. i have write this issue because the old project node red state machine create a global instance state machine for every node. but if xstate is stateless resolve my problems now

RGNagel commented 3 years ago

I think I have a similar use case.

I need to keep a separate instance of the same state machine for every device that is added automatically into node-red via mqtt.

Is this possible with the current version?

sonntam commented 3 years ago

I think I have a similar use case.

I need to keep a separate instance of the same state machine for every device that is added automatically into node-red via mqtt.

Is this possible with the current version?

@RGNagel: I think it could be possible as xstate offers invoked service functionality. Each invoked service can be a dynamically created state machine instance itself that can communicate to and from a main state-machine and manage its own context. I haven't used that functionality yet so I'm afraid I can't give you a tangible example.

However, I think debugging such a state machine in node-red is very cumbersome as the visualization on the sidebar currently only allows for visualizing the "main" state-machine.

RGNagel commented 3 years ago

Thank you for your feedback. I am going to take a look on it.

tomaszt762 commented 2 years ago

Hi ! Is there any news in this thread? I’m also interested in such feature.