1Event(3) OCaml library Event(3)
2
3
4
6 Event - First-class synchronous communication.
7
9 Module Event
10
12 Module Event
13 : sig end
14
15
16 First-class synchronous communication.
17
18 This module implements synchronous inter-thread communications over
19 channels. As in John Reppy's Concurrent ML system, the communication
20 events are first-class values: they can be built and combined indepen‐
21 dently before being offered for communication.
22
23
24
25
26
27 type 'a channel
28
29
30 The type of communication channels carrying values of type 'a .
31
32
33
34 val new_channel : unit -> 'a channel
35
36 Return a new channel.
37
38
39 type +'a event
40
41
42 The type of communication events returning a result of type 'a .
43
44
45
46 val send : 'a channel -> 'a -> unit event
47
48
49 send ch v returns the event consisting in sending the value v over the
50 channel ch . The result value of this event is () .
51
52
53
54 val receive : 'a channel -> 'a event
55
56
57 receive ch returns the event consisting in receiving a value from the
58 channel ch . The result value of this event is the value received.
59
60
61
62 val always : 'a -> 'a event
63
64
65 always v returns an event that is always ready for synchronization.
66 The result value of this event is v .
67
68
69
70 val choose : 'a event list -> 'a event
71
72
73 choose evl returns the event that is the alternative of all the events
74 in the list evl .
75
76
77
78 val wrap : 'a event -> ('a -> 'b) -> 'b event
79
80
81 wrap ev fn returns the event that performs the same communications as
82 ev , then applies the post-processing function fn on the return value.
83
84
85
86 val wrap_abort : 'a event -> (unit -> unit) -> 'a event
87
88
89 wrap_abort ev fn returns the event that performs the same communica‐
90 tions as ev , but if it is not selected the function fn is called after
91 the synchronization.
92
93
94
95 val guard : (unit -> 'a event) -> 'a event
96
97
98 guard fn returns the event that, when synchronized, computes fn() and
99 behaves as the resulting event. This enables computing events with
100 side-effects at the time of the synchronization operation.
101
102
103
104 val sync : 'a event -> 'a
105
106 'Synchronize' on an event: offer all the communication possibilities
107 specified in the event to the outside world, and block until one of the
108 communications succeed. The result value of that communication is
109 returned.
110
111
112
113 val select : 'a event list -> 'a
114
115 'Synchronize' on an alternative of events. select evl is shorthand for
116 sync(choose evl) .
117
118
119
120 val poll : 'a event -> 'a option
121
122 Non-blocking version of Event.sync : offer all the communication possi‐
123 bilities specified in the event to the outside world, and if one can
124 take place immediately, perform it and return Some r where r is the
125 result value of that communication. Otherwise, return None without
126 blocking.
127
128
129
130
131
132OCamldoc 2020-02-27 Event(3)