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 v returns the event consisting in sending the value v over the channel ch. The result value of this event is (). it's giving "send it and return unit" πŸ’Œ
  • val receive : 'a channel -> 'a event β€” receive ch returns the event consisting in receiving a value from the channel ch. The result value of this event is the value received. iconic behavior, honestly. 🎁
  • val always : 'a -> 'a event β€” always v returns an event that is always ready for synchronization. The result value of this event is v. always ready, main character energy. πŸ‘‘
  • val choose : 'a event list -> 'a event β€” choose evl returns the event that is the alternative of all the events in the list evl. pick a lane? no bestie, offer all the alternatives. 🌸
  • val wrap : 'a event -> ('a -> 'b) -> 'b event β€” wrap ev fn returns the event that performs the same communications as ev, then applies the post-processing function fn on the return value. glow-up your result value, fr fr. πŸ’…
  • val wrap_abort : 'a event -> (unit -> unit) -> 'a event β€” wrap_abort ev fn returns the event that performs the same communications as ev, but if it is not selected the function fn is called after the synchronization. lowkey the cleanup crew. 🧹
  • val guard : (unit -> 'a event) -> 'a event β€” guard fn returns the event that, when synchronized, computes fn() 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 evl is shorthand for sync(choose evl). literally the combo move. πŸ”₯
  • val poll : 'a event -> 'a option β€” Non-blocking version of Event.sync: offer all the communication possibilities specified in the event to the outside world, and if one can take place immediately, perform it and return Some r where r is the result value of that communication. Otherwise, return None without 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