Skip to content

Commit

Permalink
Add some additional comments
Browse files Browse the repository at this point in the history
Elaborates on the logic of the blocking queue offer.
  • Loading branch information
rzeigler committed Apr 15, 2019
1 parent c0e77ae commit ed245da
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/queue/blocking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,28 @@ export class CloseableAsyncQueueImpl<A> {
// The queue is closed, so we need to ensure we are draining
if (current.closed) {
return current.queue.fold<[Ticket<Option<A>>, CloseableQueueState<A>]>(
// we are queued up on waits, so we can do nothing
(waiting) => [new Ticket(IO.of(none), IO.void()), {...current, queue: left(waiting)}],
(available) => {
const [next, queue] = available.dequeue();
// there is an available element so we should drain it
if (next) {
return [
new Ticket(IO.of(next), IO.void()),
{...current, queue: right(queue)}
];
}
// otherwise there is nothing we can do
return [
new Ticket(IO.of(none), IO.void()),
{...current, queue: left(Dequeue.empty())}
];
}
);
} else {
// The queue is not closed
// We want to construct tickets that wait on the constructed deferred and the closed implementation
// The tickets should also always remove the deferred from the queue
const cleanup = this.unregister(deferred);
return current.queue.fold<[Ticket<Option<A>>, CloseableQueueState<A>]>(
(waiting) => [
Expand Down

0 comments on commit ed245da

Please sign in to comment.