module Callback_arity : sig ... endCallback_aritystates the type of callbacks stored in a bus. UsingCallback_arityis an implementation technique that allows callbacks to be defined as ordinary n-ary curried functions (e.g.,a1 -> a2 -> a3 -> r), instead of forcing n-ary-variadic callbacks to use tuples (e.g.,a1 * a2 * a3 -> r). This also avoids extra allocation.
val sexp_of_t : ('callback -> Ppx_sexp_conv_lib.Sexp.t) -> ('phantom -> Ppx_sexp_conv_lib.Sexp.t) -> ('callback, 'phantom) t -> Ppx_sexp_conv_lib.Sexp.t
type ('callback, 'phantom) bus = ('callback, 'phantom) t
module Read_write : sig ... endmodule Read_only : sig ... endmodule On_subscription_after_first_write : sig ... endval read_only : ('callback, _) t -> 'callback Read_only.tval create : ?name:Core_kernel.Info.t -> Core_kernel.Source_code_position.t -> 'callback Callback_arity.t -> on_subscription_after_first_write:On_subscription_after_first_write.t -> on_callback_raise:(Core_kernel.Error.t -> unit) -> 'callback Read_write.tIn
create [%here] ArityN ~on_subscription_after_first_write ~on_callback_raise,[%here]is stored in the resulting bus, and contained in%sexp_of: t, which can help with debugging.If
on_subscription_after_first_writeisRaise, thensubscribe_exnwill raise if it is called afterwritehas been called the first time. Ifon_subscription_after_first_writeisAllow_and_send_last_value, then the bus will remember the last value written and will send it to new subscribers.If a callback raises,
on_callback_raiseis called with an error containing the exception.If
on_callback_raiseraises, then the exception is raised towriteand the bus is closed.
val callback_arity : ('callback, _) t -> 'callback Callback_arity.tval num_subscribers : (_, _) t -> intval is_closed : (_, _) t -> boolval close : 'callback Read_write.t -> unitclosedisallows futurewrites -- onceclose tis called, all further calls towrite twill raise.closeis idempotent. Ifcloseis called from within a callback, the current message will still be sent to all subscribed callbacks that have not yet seen it before the close takes effect.
val write : ('a -> unit) Read_write.t -> 'a -> unitval write2 : ('a -> 'b -> unit) Read_write.t -> 'a -> 'b -> unitval write3 : ('a -> 'b -> 'c -> unit) Read_write.t -> 'a -> 'b -> 'c -> unitval write4 : ('a -> 'b -> 'c -> 'd -> unit) Read_write.t -> 'a -> 'b -> 'c -> 'd -> unitval write5 : ('a -> 'b -> 'c -> 'd -> 'e -> unit) Read_write.t -> 'a -> 'b -> 'c -> 'd -> 'e -> unit
module Subscriber : sig ... endval subscribe_exn : ?extract_exn:bool -> ?on_callback_raise:(Core_kernel.Error.t -> unit) -> ?on_close:(unit -> unit) -> ('callback, [> Core_kernel.read ]) t -> Core_kernel.Source_code_position.t -> f:'callback -> 'callback Subscriber.tsubscribe_exn t [%here] ~fadds the callbackfto the set oft's subscribers, and returns aSubscriber.tthat can later be used tounsubscribe.[%here]is stored in theSubscriber.t, and contained in%sexp_of: Subscriber.t, which can help with debugging. Ifsubscribe_exn tis called by a callback int, i.e., duringwrite t, the subscription takes effect for the nextwrite, but does not affect the currentwrite.subscribe_exntakes amortized constant time.If
on_callback_raiseis supplied, then it will be called bywritewheneverfraises; only if that subsequently raises willt'son_callback_raisebe called. Ifon_callback_raiseis not supplied, thent'son_callback_raisewill be called wheneverfraises.If
on_callback_raiseis supplied andextract_exnis set to true, then the error passed to theon_callback_raisemethod will contain only the exception raised byfwithout any additional information about the bus subscription or backtrace.on_closeis called if you are still subscribed whenBus.closeis called.
val iter_exn : ('callback, [> Core_kernel.read ]) t -> Core_kernel.Source_code_position.t -> f:'callback -> unititer_exn t [%here] ~fisignore (subscribe_exn t [%here] ~callback:f). This captures the common usage in which one never wants to unsubscribe from a bus.
module Fold_arity : sig ... endval fold_exn : ('callback, [> Core_kernel.read ]) t -> Core_kernel.Source_code_position.t -> ('callback, 'f, 's) Fold_arity.t -> init:'s -> f:'f -> unitfold_exn t [%here] arity ~init ~ffolds over the bus events, threading a state value to every call. It is otherwise similar toiter_exn.
val unsubscribe : ('callback, [> Core_kernel.read ]) t -> 'callback Subscriber.t -> unitunsubscribe t subscriberremoves the callback corresponding tosubscriberfromt.unsubscribenever raises and is idempotent. As withsubscribe_exn,unsubscribe tduringwrite ttakes effect after the currentwritefinishes. Also likesubscribe_exn,unsubscribetakes amortized constant time.