pragmatrix / Mom

MOnadic Machines: F# computation expressions and combinators for deterministic coordination, simulation, and testing of concurrent processes.
1 stars 0 forks source link

Extend the arbiter to be able to handle and trigger events. #30

Open pragmatrix opened 5 years ago

pragmatrix commented 5 years ago

For a new requirement, and to make the control function of the arbiter more similar to an ELM-like update function, the arbiter needs to be able to cancel moms that are active in its field.

The implementation is split into two parts:

Cancellable Moms

To convert a simple mom into an externally cancellable mom, it may just be wrapped in an Mom.any [ waitFor CancellationEvent; mom ], and as soon the CancellationEvent is received, mom will be cancelled. To avoid conflicts when many of the same cancellable moms are running, the CancellationEvent needs to be unique. To ensure that, unique Ids need to be generated.

Two types of cancellable Moms should be supported. Hard and soft cancellation.

Adding Runtime Features to the Arbiter

In addition to that, the Arbiter needs to be able to schedule events (a feature the runtime itself supports so far only), and although it is a not a direct requirement, it seems that the Arbiter should also be able to react to events, too. So the input to the arbiter (currently 'state and 'r result) will be changed to a sum type similar to the follwing:

type ArbiterMessage<'r> = 
  | MomCompleted of 'r result
  | Event of obj

and the signature changes to 'state -> ArbiterMessage<'r> -> ArbiterDecision<'state, 'r>

and the ArbiterDecision's ContinueField needs an additional tuple argument that defines a list of events that need to be scheduled into the field.

This is a breaking change and the semantics for that are not entirely pinned down yet.