Closed gepz closed 1 year ago
I think the reason is that scope created here suspend fun makeM() = coroutineScope {
and used in state machine here createStateMachine(this)
is already cancelled when you call m.exportToPlantUml()
.
Check this version, please.
Does the scope used by the factory function have to exist throughout the entire life time of the state machine? If so, how can I save the machine as a variable?
Yes life time of a scope should be equal or longer then machine lifetime. There is no problem with storing machine as variable. Just create your couroutine scope or use standard one (like GlobalScope). The reason of your problem is that you are using coroutineScope
function which is not designed for scope creation, but for parallel decomposition of work.
https://kt.academy/article/cc-constructing-scope here you can find samples of scope creation that I mean.
Actually to call coroutineScope
you already need to have a scope, you have created it by runTest
block in your sample.
I see, thanks for the info.
The above JUnit5 test testUML will throw JobCancellationException for some reason. It wouldn't if I put
val uml = m.exportToPlantUml()
inside makeM though. I'm corrently using the legacy non-coroutine method as the workaround