package sel

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module SelSource

Simple event library - No asymc monads, No threads, No exceptions

Sourcetype 'a event
Sourcetype 'a res = ('a, exn) result
Sourcetype cancellation_handle
Sourceval cancel : cancellation_handle -> unit
Sourceval on_line : Unix.file_descr -> (string res -> 'a) -> 'a event * cancellation_handle

System events one can wait for

Sourceval on_bytes : Unix.file_descr -> int -> (Bytes.t res -> 'a) -> 'a event * cancellation_handle
Sourceval on_death_of : pid:int -> (Unix.process_status -> 'a) -> 'a event * cancellation_handle
Sourceval on_ocaml_value : Unix.file_descr -> ('b res -> 'a) -> 'a event * cancellation_handle
Sourceval on_httpcle : Unix.file_descr -> (Bytes.t res -> 'a) -> 'a event * cancellation_handle
Sourceval on_queues : 'b Queue.t -> 'c Queue.t -> ('b -> 'c -> 'a) -> 'a event * cancellation_handle

Synchronization events between components (worker pool and a task queue)

Sourceval on_queue : 'b Queue.t -> ('b -> 'a) -> 'a event * cancellation_handle

A way to feed the event queue

Sourceval now : 'a -> 'a event

Mix regular computations with blocking event (reified)

Sourceval map : ('a -> 'b) -> 'a event -> 'b event
Sourceval name : string -> 'a event -> 'a event

for debug printing

a recurrent event is never removed from the todo set, that is, when ready a copy of it is added back automatically

Sourceval make_recurring : 'a event -> 'a event

a recurrent event is never removed from the todo set, that is, when ready a copy of it is added back automatically

convenience adaptor to drop the cancellation handle

Sourceval uncancellable : ('a event * cancellation_handle) -> 'a event

convenience adaptor to drop the cancellation handle

it is unusual to make a regular computation cancellable, hence the event constructor does not recurn the cancellation handle. Here the way to recover it

Sourceval cancellation_handle : 'e event -> cancellation_handle

it is unusual to make a regular computation cancellable, hence the event constructor does not recurn the cancellation handle. Here the way to recover it

lower integers correspond to hight priorities (as in Unix nice)

Sourceval set_priority : int -> 'a event -> 'a event

lower integers correspond to hight priorities (as in Unix nice)

The main loop goes like this

type top_event = | NotForMe of Component.event | Echo of string

let echo : top_event event = on_line Unix.stdin (function | Ok s -> Echo s | Error _ -> Echo "error") |> uncancellable |> make_recurrent

let handle_event = function | NotForMe e -> List.map (map (fun x -> NotForMe x)) (Component.handle_event e) | Echo text -> Printf.eprintf "echo: %s\n" text;

let rec loop evs = let ready, evs = pop evs in let new_evs = handle_event ready in loop (enqueue evs new_evs)

let main () = loop (enqueue empty echo; ...)

Sourcetype 'a todo
Sourceval pp_todo : (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a todo -> unit
Sourceval empty : 'a todo
Sourceval size : 'a todo -> int
Sourceval enqueue : 'a todo -> 'a event list -> 'a todo
Sourceval nothing_left_to_do : 'a todo -> bool
Sourceval only_recurring_events : 'a todo -> bool
Sourceval pop : 'a todo -> 'a * 'a todo

raises Failure if there is nothing left to do

Sourceval pop_opt : 'a todo -> 'a option * 'a todo
Sourceval pop_timeout : stop_after_being_idle_for:float -> 'a todo -> 'a option * 'a todo
Sourceval wait : 'a todo -> 'a list * 'a list * 'a list * 'a todo
Sourceval wait_timeout : stop_after_being_idle_for:float -> 'a todo -> 'a list * 'a list * 'a list * 'a todo
OCaml

Innovation. Community. Security.