Skip to content

Commit 28eaefd

Browse files
committed
add validation for queue size
1 parent b5d7841 commit 28eaefd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/aqueue/aqueue.mbt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ struct Queue[X] {
6666
#as_free_fn
6767
#callsite(migration(kind, fill=true, msg="specify the kind of queue explicitly via `kind=...`"))
6868
pub fn[X] Queue::new(kind? : Kind = Unbounded) -> Queue[X] {
69+
match kind {
70+
Unbounded => ()
71+
Blocking(n) | DiscardOldest(n) | DiscardLatest(n) =>
72+
if n <= 0 {
73+
abort("queue size must be positive")
74+
}
75+
}
6976
{ kind, writers: @deque.new(), readers: @deque.new(), buffer: @deque.new() }
7077
}
7178

0 commit comments

Comments
 (0)