evReact
Checkout the new
and start playing with evReact!What
Reactive programming is important ingredient since reactive systems (as defined by the Reactive Manifesto) are becoming so widely developed. The evReact library is an event based control flow management library for supporting this type of programming.
Using few compositional operators it is possible to define an event-tracking system that allows to fire handlers only when a particular sequence of events is detected.
We believe that the approach we adopted for evReact has the potential to become a primitive construct for programming languages.
Why
Using this lightweight support for recognizing sequence of events it is possible to overlay workflows into programs. There are several applications including:
- Compositional gesture recognition like the one in the GestIT library
- Control flow serialization is possible since evReact control flow is represented as a serializable data structure.
- Internal program tracking for ensuring that the program is in a well known macrostate before executing some code.
- Hierarchical event handling (i.e. expressions recognizing different but analogous events fire meta events into other expressions).
- Handling related events with unbound arguments (i.e. multitouch events with arbitrary number of touches).
- The model supports event orchestration across different processes, supporting distributed application development like Web apps.
- The framework is so lightweight it can run almost everywhere, including in the typical IoT devices.
Expressions generates Petri networks that are responsible for recognizing the event sequences. Generated Nets are not Turing Complete, though completeness is achievable by dynamic net generation. This ensures a good mix of verifiability and expressivity.
Where
The evReact library is primarily developed in F# and is available to .NET languages. We are adding ports to other programming systems the programming model. The TypeScript/JavaScript implementation is already available. Python and Java implementations are under development.
How
The programming model of evReact is based on composing events with a small list of operators:
Operator | F# syntax | Description |
---|---|---|
Ground | !! |
This operator is used to bind an event to a node of the expression. |
Filtered ground | %- |
This operator is similar to !! but it allows to accept events
only if a given condition is met.
|
Action | |-> |
With the action operator it is possible to invoke a function when an expression recognizes an event pattern. |
Fault handling | |=> |
Like in the try/finally construct of many languages, this operator allows to
execute an action when an expression either completes or fails.
|
Sequence | - |
With the sequence operator it is possible to recognize an event only
after another (or an expression involving events) happened. For instance
the expression !!A - (!!B |-> fun () -> printfn "B!") prints
B! only after the event A happens.
|
Iter | + |
If an expression involving events is prefixed with this operator, the event pattern can be recognized multiple times. |
All | &&& |
The expression (!!A &&& !!B &&& !!C) recognizes
the events A , B and C and completes only when
all the three events are recognized.
|
Any | ||| |
This operator is similar to the &&&
operator but in this case whenever any of the subexpressions
completes, the whole expression completes (and the
recognition of the other subexpressions is continued).
|
Restrict | / |
The event recognizer usually ignores events different from those expected by an expression.
For instance in the sequence (!!A - !!B) if A is expected and B
or any other event happens, those events are ignored. The restriction operator allows to restrict an expression
over a given alphabet of events; for instance in (!!A - !!B)/[|A;B|] if B happens
while A is expected the whole recognition fails.
|
Who
evReact is a library with a quite long history. The early studies on how to use Petri Nets for recognizing complex events sequences for composable gesture recognition were conducted by Davide Spano during his PhD, under the supervision of Prof. Antonio Cisternino (@cisterni). This led to a first implementation of GestIT with a strict semantics developed in C#. The library was then re-designed and re-implemented using F# with a better and more composable semantics by Andrea Canciani and Marta Martino. During the second implementation we found the programming model widely applicable than just the gesture definitions. This led to the current evReact implementation (and PhD work) by Andrea Canciani under the supervision of Prof. Antonio Cisternino. GestIT will be eventually rewritten based on evReact. Under this last rewriting more attention has been paid to critical aspects of semantics such as concurrency.