Module Bus

An Async extension of Core_kernel.Bus. Functions that share the same name and types as those in Core_kernel.Bus are direct calls to the same.


type ('callback, 'phantom) t = ('callback, 'phantom) Core_kernel.Bus.t
val sexp_of_t : ('callback -> Sexplib.Sexp.t) -> ('phantom -> Sexplib.Sexp.t) -> ('callback, 'phantom) t -> Sexplib.Sexp.t
type ('callback, 'phantom) bus = ('callback, 'phantom) t
val read_only : ('callback, 'a) t -> 'callback Read_only.t
val create : ?name:Core_kernel.Info.t -> Core_kernel.Source_code_position.t -> 'callback Callback_arity.t -> allow_subscription_after_first_write:bool -> on_callback_raise:(Core_kernel.Error.t -> unit) -> 'callback Read_write.t
val callback_arity : ('callback, 'a) t -> 'callback Callback_arity.t
val num_subscribers : ('a, 'b) t -> int
val is_closed : ('a, 'b) t -> bool
val close : 'callback Read_write.t -> unit
val write : 'callback Read_write.t -> 'callback
val subscribe_exn : ?on_callback_raise:(Core_kernel.Error.t -> unit) -> 'callback Read_only.t -> Core_kernel.Source_code_position.t -> f:'callback -> 'callback Subscriber.t
val iter_exn : 'callback Read_only.t -> Core_kernel.Source_code_position.t -> f:'callback -> unit
val fold_exn : 'callback Read_only.t -> Core_kernel.Source_code_position.t -> ('callback, 'f, 's) Fold_arity.t -> init:'s -> f:'f -> unit
val unsubscribe : 'callback Read_only.t -> 'callback Subscriber.t -> unit
val pipe1_exn : ('a -> unit) Read_only.t -> 'a Import.Pipe.Reader.t

pipe1_exn t returns a pipe of updates from t. If the pipe is closed you will be unsubscribed. pipe1_exn raises in the same circumstances as subscribe_exn.

module First_arity : sig .. end
val first_exn : 'c Read_only.t -> Core.Std.Source_code_position.t -> ('c, 'f, 'r) First_arity.t -> f:'f -> 'r Import.Deferred.t

first_exn here t arity ~f returns a deferred that becomes determined with value r when the first event is published to t where f returns Some r. first_exn then unsubscribes from t, ensuring that f is never called again after it returns Some. first_exn raises if it can't subscribe to the bus, i.e. if subscribe_exn raises. If f raises, then first_exn raises to the monitor in effect when first_exn was called. first_exn takes time proportional to the number of bus subscribers.