mirror of
https://github.com/ocaml-multicore/eio.git
synced 2025-11-27 00:04:06 -05:00
Merge pull request #141 from bikallem/stream-is_empty
lib_eio: implement Stream.is_empty
This commit is contained in:
commit
ccc62f5530
@ -308,6 +308,12 @@ module Stream : sig
|
||||
it returns [None] if the stream is empty rather than waiting.
|
||||
Note that if another domain may add to the stream then a [None]
|
||||
result may already be out-of-date by the time this returns. *)
|
||||
|
||||
val length : 'a t -> int
|
||||
(** [length t] returns the number of items currently in [t]. *)
|
||||
|
||||
val is_empty : 'a t -> bool
|
||||
(** [is_empty t] is [length t = 0]. *)
|
||||
end
|
||||
|
||||
(** Cancelling other fibres when an exception occurs. *)
|
||||
|
||||
@ -118,3 +118,11 @@ let take_nonblocking t =
|
||||
end;
|
||||
Mutex.unlock t.mutex;
|
||||
Some v
|
||||
|
||||
let length t =
|
||||
Mutex.lock t.mutex;
|
||||
let len = Queue.length t.items in
|
||||
Mutex.unlock t.mutex;
|
||||
len
|
||||
|
||||
let is_empty t = (length t = 0)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user