Event(3)
π Event β first-class synchronous communication π
okay so this is the Event(3) page from the OCaml library manual, and I'm obsessed β it's literally about first-class synchronous communication, no cap. bestie, this page ate and left no crumbs π
β¨
πΈ NAME πΈ
Event β First-class synchronous communication. periodt. π
π§ Module π§
Module Event β yes bestie, that's the module. its signature is sig end, and that's the whole vibe. π¦
β¨ Documentation β¨
Module Event : sig end
This module implements synchronous inter-thread communications over channels. As in John Reppy's Concurrent ML system, the communication events are first-class values: they can be built and combined independently before being offered for communication. the way that works is genuinely iconic β build the event first, offer it later, no cap. π
type 'a channelβ the type of communication channels carrying values of type'a. your little pipe for values, but make it typed, bestie. πval new_channel : unit -> 'a channelβ Return a new channel. fresh channel, who dis? β¨type +'a eventβ the type of communication events returning a result of type'a. note the+in the signature, iykyk. π«val send : 'a channel -> 'a -> unit eventβsend ch vreturns the event consisting in sending the valuevover the channelch. The result value of this event is(). it's giving "send it and return unit" πval receive : 'a channel -> 'a eventβreceive chreturns the event consisting in receiving a value from the channelch. The result value of this event is the value received. iconic behavior, honestly. πval always : 'a -> 'a eventβalways vreturns an event that is always ready for synchronization. The result value of this event isv. always ready, main character energy. πval choose : 'a event list -> 'a eventβchoose evlreturns the event that is the alternative of all the events in the listevl. pick a lane? no bestie, offer all the alternatives. πΈval wrap : 'a event -> ('a -> 'b) -> 'b eventβwrap ev fnreturns the event that performs the same communications asev, then applies the post-processing functionfnon the return value. glow-up your result value, fr fr. πval wrap_abort : 'a event -> (unit -> unit) -> 'a eventβwrap_abort ev fnreturns the event that performs the same communications asev, but if it is not selected the functionfnis called after the synchronization. lowkey the cleanup crew. π§Ήval guard : (unit -> 'a event) -> 'a eventβguard fnreturns the event that, when synchronized, computesfn()and behaves as the resulting event. This enables computing events with side-effects at the time of the synchronization operation. big "build the event when it's go time" energy. β°val sync : 'a event -> 'aβ 'Synchronize' on an event: offer all the communication possibilities specified in the event to the outside world, and block until one of the communications succeed. The result value of that communication is returned. yes bestie, this is the blocking one β it waits. πval select : 'a event list -> 'aβ 'Synchronize' on an alternative of events.select evlis shorthand forsync(choose evl). literally the combo move. π₯val poll : 'a event -> 'a optionβ Non-blocking version ofEvent.sync: offer all the communication possibilities specified in the event to the outside world, and if one can take place immediately, perform it and returnSome rwhereris the result value of that communication. Otherwise, returnNonewithout blocking. no waiting around, no cap. π«Ά
π that's the whole page, bestie β source/version: OCamldoc, date: 2026-06-22. mwah π«Άπ
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms