Module Clock


module Clock: sig .. end
Clocks indicate at which rate a source can be read, thus avoiding by typing the need for infinite buffering.

class clock : string -> Source.clock
Base clock class.
class wallclock : ?sync:bool -> string -> clock
class self_sync : string -> object .. end
val running : unit -> bool
Does the application have started to run?

Global clock management



When created, sources have a clock variable, which gets unified with other variables or concrete clocks. When the time comes to initialize the source, if its clock isn't defined yet, it gets assigned to a default clock and that clock will take care of starting it.

Taking all freshly created sources, assigning them to the default clock if needed, and starting them, is performed by collect. This is typically called after each script execution. Technically we could separate collection and clock assignment, which might simplify some things if it becomes unmanageable in the future.

Sometimes we need to be sure that collect doesn't happen during the execution of a function. Otherwise, sources might be assigned the default clock too early. This is done using collect_after. This need is not cause by running collect in too many places, but simply because there is no way to control collection on a per-thread basis (collect only the sources created by a given thread of script execution).

Functions running using collect_after should be kept short. However, in theory, with multiple threads, we could have plenty of short functions always overlapping so that collection can never be done. This shouldn't happen too much, but in any case we can't get rid of this without a more fine-grained collect, which would require (heavy) execution contexts to tell from which thread/code a given source has been added.

val collect_after : (unit -> 'a) -> 'a
val force_init : (Source.active_source -> bool) -> Source.active_source list
Initialize only some sources, recognized by a filter function. The advantage over collect is that it is synchronous and a list of errors (sources that failed to initialize) is returned.
val start : unit -> unit
val stop : unit -> unit
To stop, simply detach everything and the clocks will stop running. No need to collect, stopping is done by itself.
val fold : (Source.clock -> 'a -> 'a) -> 'a -> 'a
type clock_variable = Source.clock_variable 
val to_string : clock_variable -> string
val create_unknown : sources:Source.active_source list ->
sub_clocks:clock_variable list -> clock_variable
val create_known : clock -> clock_variable
val unify : clock_variable -> clock_variable -> unit
val get : clock_variable -> Source.clock