anatoliykmetyuk / free-acp

A rewriting-based process algebra engine
7 stars 3 forks source link

Resumption should listen on all the choices simultaniously #18

Closed anatoliykmetyuk closed 7 years ago

anatoliykmetyuk commented 7 years ago

Currently, the tree that needs resumption is processed as follows:

            resume.apply(t)
              .map((f.apply[Tree[S]] _) andThen G.extract andThen rewriteLoop)
              .find(!_.isInstanceOf[Failure[S]])
              .getOrElse(Failure[S]())

All the elements are mapped with G.extract in order. G.extract may be blocking, like Await.result on a Future. So one choice that never happens may prevent all the subsequent ones from being considered.

Instead, what is needed is a kind of an Observable which will try to extract all the choices simultaneously and will emit them in order in which they happen.

The first choice that does not evaluate to Failure should be considered. Optionally, the remaining choices should be cancelled, allowing them to terminate gracefully.