@@ -12,33 +12,58 @@ exception Closed
12
12
val create : unit -> 'a t
13
13
(* * [create ()] returns a new empty queue. *)
14
14
15
+ val is_empty : 'a t -> bool
16
+ (* * [is_empty q] is [true] if calling [pop] would return [None].
17
+
18
+ @raise Closed if [q] is closed and empty. *)
19
+
20
+ val close : 'a t -> unit
21
+ (* * [close q] marks [q] as closed, preventing any further items from
22
+ being pushed by the producers (i.e. with {!push}).
23
+
24
+ @raise Closed if [q] has already been closed. *)
25
+
15
26
val push : 'a t -> 'a -> unit
16
- (* * [push q v] adds the element [v] at the end of the queue [q]. This
27
+ (* * [push q v] adds the element [v] at the end of the queue [q]. This
17
28
can be used safely by multiple producer domains, in parallel with
18
29
the other operations.
19
30
20
31
@raise Closed if [q] is closed. *)
21
32
22
- val pop : 'a t -> 'a option
23
- (* * [pop q] removes and returns the first element in queue [q] or
33
+ (* * {2 Consumer-only functions} *)
34
+
35
+ exception Empty
36
+ (* * Raised when {!pop} or {!peek} is applied to an empty queue. *)
37
+
38
+ val pop : 'a t -> 'a
39
+ (* * [pop q] removes and returns the first element in queue [q].
40
+
41
+ @raise Empty if [q] is empty.
42
+
43
+ @raise Closed if [q] is closed and empty. *)
44
+
45
+ val pop_opt : 'a t -> 'a option
46
+ (* * [pop_opt q] removes and returns the first element in queue [q] or
24
47
returns [None] if the queue is empty.
25
48
26
49
@raise Closed if [q] is closed and empty. *)
27
50
28
- val push_head : 'a t -> 'a -> unit
29
- (* * [push_head q v] adds the element [v] at the head of the queue
30
- [q]. This can only be used by the consumer (if run in parallel
31
- with {!pop}, the item might be skipped) .
51
+ val peek : 'a t -> 'a
52
+ (* * [peek q] returns the first element in queue [q].
53
+
54
+ @raise Empty if [q] is empty .
32
55
33
56
@raise Closed if [q] is closed and empty. *)
34
57
35
- val is_empty : 'a t -> bool
36
- (* * [is_empty q] is [true] if calling [pop] would return [None].
58
+ val peek_opt : 'a t -> 'a option
59
+ (* * [peek_opt q] returns the first element in queue [q] or
60
+ returns [None] if the queue is empty.
37
61
38
62
@raise Closed if [q] is closed and empty. *)
39
63
40
- val close : 'a t -> unit
41
- (* * [close q] marks [q] as closed, preventing any further items from
42
- being pushed by the producers (i.e. with {!push}).
64
+ val push_head : 'a t -> 'a -> unit
65
+ (* * [push_head q v] adds the element [v] at the head of the queue
66
+ [q]. This can only be used by the consumer (if run in parallel
67
+ with {!pop}, the item might be skipped).
43
68
44
- @raise Closed if [q] has already been closed . *)
69
+ @raise Closed if [q] is closed and empty . *)
0 commit comments