I am not sure what I am doing wrong with fulcro statecharts. I am trying to invoke a future for a long running process. I used the example invocation as a starting point, but it does not seem to be doing what I expect. Details in thread.
(state {:id :running/ai
:initial :ai/idle}
(state {:id :ai/idle}
(transition {:id :transisition/ai-idle->ai-processing
:event :chat-completion
:target :ai/processing}))
(state {:id :ai/processing}
(on-entry {:id :entry/ai-processing})
(invoke {:id :invoke/chat-completion
:type :future
:src (fn [& args]
(tap> {:from :invoke/chat-completion :args args})
(Thread/sleep 5000)
{:future-result :DONE})})
(transition {:id :transition/chat-results
:event :done.invoke.*
:target :ai/idle}
(script {:id :script/chat-results
:expr (fn [env data]
(tap> {:from :script/chat-results :env env :data data}))}))))
Fixed code, this is now working.This does not fire the tap from the invoke, or the tap from the from :done.invoke.* transition. It does transition back to the :ai/idle state though.
I'm using this to just try to see the data in the flow of states so I can figure out how to get the data from the event into the invocation. I expected all the taps to fire once I sent the :chat-completion event, the transitions seem to work, but the executable content does not seem to execute.
I originally tried to just have an invoke on a transition so the state would stay active, but invoke is not allowed on a transition. What I would like to have is the ability to run multiple long-running invocations that take the results and fire an event after they complete. My current setup just blocks while the long running process is happening and events just queue up until it completes. I would like to have multiple futures running while the statechart continues to process other events. I can't find any other examples of using invoke outside the examples provided in the statecharts repo.
first, are you using the latest version. There have been some invocation fixes in the past few versions
Yes running v1.2.22
I did some invocation work within the fulcro integration in the statecharts library itself
but it’s all invoking other charts. The “futures” implementation of invocations in the book may be incorrect or out of date? When I wrote what is there I’m sure I tested it
Yes that works actually, I'm sorry to give the impression it was your code that was not working. My code is not exactly the same, I meant that I had started with the example and tried to adapt it to my multiple futures setup.
oh
did you remember to install a tap handler?
Yes I see taps from other parts of the statechart, this is just one small parallel state
nothing stands out…it looks just like mine
which you say works
the transition :transisition/ai-idle->ai-processing doesn't have a target
Wow. I have been looking at this thing since last night and didn't see it. That fixed it, thank you very much.