KStateMachine / kstatemachine

KStateMachine is a Kotlin DSL library for creating state machines and statecharts.
https://kstatemachine.github.io/kstatemachine/
Boost Software License 1.0
339 stars 19 forks source link

Question on state chart per thread limitation? #70

Closed aedenj closed 11 months ago

aedenj commented 11 months ago

First of all, great work. It's my understanding that there is a state chart per thread which is quite resource intensive for certain use cases. If i'm interested in tracking and measuring the result of events, think json payload, coming from possibly millions of IOT devices. The stream of events will contain events for numerous IOT devices each with their of state chart. I don't want to have millions of threads going. Is there any way around this start chart per thread limitation of this library?

nsk90 commented 11 months ago

Hi! thanks. The limitation is that only one thread may touch StateMachine at a moment. So if you have many threads that want to post events to some StateMachine, it should be synchronized externally. Or you can run StateMachine on worker thread and post events to that thread via queue from other ones.

You can run as many StateMachines on the single thread as you need, it is not limited. StateMachine does not block the thread (there is no infinite loop inside).

Sorry, if I understood your question wrong.

nsk90 commented 11 months ago

Closing?

aedenj commented 11 months ago

Yes, thank for responding. Ultimately my issue was I was using object states and when I would create another machine I was misinterrupting the reason. In general is this the appropriate place for usage questions?

nsk90 commented 11 months ago

https://github.com/nsk90/kstatemachine/discussions Better place for questions here, I think.