matthewp / robot

🤖 A functional, immutable Finite State Machine library
https://thisrobot.life
BSD 2-Clause "Simplified" License
1.92k stars 88 forks source link

Allow `action()`s to send events back to the fsm #181

Closed ehuelsmann closed 1 year ago

ehuelsmann commented 2 years ago

Currently action()s only have the context record available as it was at the time the action was invoked. However, some actions, especially longer running ones, may want to send events back to the FSM. This happens when the FSM should continue its regular behaviour (in my case: coordinating the state of the UI) while the asynchronous/long running action does its work and sends events (i.e. data) to the FSM. This is especially a problem when multiple instances of the FSM are active at the same time and therefor a "singleton" pattern won't work to identify the FSM to send the events to.

The solution here could be to provide not only the context, but also the "send" function as an argument to the action function.

ehuelsmann commented 1 year ago

Closing as I have much more priority for #180 .

johnwheeler commented 5 months ago

Hi @ehuelsmann I'm running into this exact problem right now. How do you get around it?