package sel
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module SelSource
Simple event library
The main loop goes like this
type top_event =
| NotForMe of Component.Event.t
| Echo of string
let echo : top_event Event.t =
On.line Unix.stdin (function
| Ok s -> Echo s
| Error _ -> Echo "error")
let handle_event = function
| NotForMe e ->
Component.handle_event e |>
List.map (Event.map (fun x -> NotForMe x))
| Echo text ->
Printf.eprintf "echo: %s\n" text;
[echo]
let rec loop evs =
let ready, evs = Todo.pop evs in
let new_evs = handle_event ready in
loop (Todo.add evs new_evs)
let main () =
loop (Todo.add Todo.empty [echo; ...])
module Event : sig ... endThe type of events and operations (setting priority, cancelling, ...)
module Promise : sig ... endSimple promise library for synchronization. There is no critical section support: if two threads run if not (is_resolved p) then fulfill r the behavior is undefined. Use only in a 1 producer 1 consumer scenario.
module On : sig ... endEvents one can wait for (read data, pull from queues, ...)
val now : ?priority:int -> ?name:string -> 'a -> 'a Event.tmix a regular computations with blocking events. E.g. to make a fold interruptible one can do something like:
type event =
| Fold of (int -> int -> int) * int * int list
| Other
let handle_event = function
| Other -> ...
| Fold(_,acc,[]) -> Printf "done: %s\n" acc; []
| Fold(f,acc,x::xs) -> [now (Fold (f, f acc x, xs))
let main =
let rec loop todo =
match pop_opt todo with
| None -> exit 0
| Some e ->
let es = handle_event e in
loop (Todo.add todo es)
in
loop (Todo.add Todo.empty [now (Fold((+),0,[1;2;3])); ...])wait for one event. If more are ready, return the one with higher priority.
same as pop_opt but retuning a None if no event is ready in stop_after_being_idle_for seconds. Precision is about a tenth of a second.
waits until some event is ready. All ready events with the lowest priority are returned.