Module Opentelemetry_util.AswitchSource

Aswitch for level-triggered cancellation and cleanup, atomically.

A switch can be flipped to false once, and remains off forever afterwards.

Inspired from https://ocsigen.org/lwt/5.5.0/api/Lwt_switch but thread-safe.

Sourcetype t
Sourcetype trigger

Can be used to turn the switch off

Sourceval pp : Format.formatter -> t -> unit
Sourceval show : t -> string
Sourceval create : ?parent:t -> unit -> t * trigger

New switch.

  • parameter parent

    inherit from this switch. It means that the result switches off if the parent does, but conversely we can turn the result off without affecting the parent. In other words, this switch's lifetime is a subset of the parent's lifetime

Sourceval on_turn_off : t -> (unit -> unit) -> unit

on_turn_off sw f will call f() when sw is turned off. If sw is already off then f() is called immediately.

NOTE f really should not fail, and should be as fast and light as possible.

Sourceval is_on : t -> bool
Sourceval is_off : t -> bool
Sourceval turn_off : trigger -> unit
Sourceval turn_off' : trigger -> [ `Was_off | `Was_on ]

Turn off switch, return previous state

link parent trigger turns off trigger when parent is turned off

Sourceval dummy : t

Always off switch

Sourcemodule Unsafe : sig ... end