-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdf4d5f
commit 825dbb0
Showing
8 changed files
with
204 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,58 @@ import { assert } from "https://deno.land/[email protected]/assert/assert.ts"; | |
import { QueueClosedError, QueueFullError, QueueReadOnlyError } from "./errors.ts"; | ||
import { assertRejects } from "https://deno.land/[email protected]/assert/assert_rejects.ts"; | ||
import { asyncQueue } from './asyncQueue.ts'; | ||
import { waitGroup } from "../WaitGroup.ts"; | ||
|
||
Deno.test("AsyncQueue on dequeue test", async () => { | ||
let dequeued = 0; | ||
let queued = 0; | ||
let dequeuedOnce = 0; | ||
let queuedOnce = 0; | ||
|
||
const wg = waitGroup(8); | ||
|
||
const queue = asyncQueue<number>(); | ||
|
||
queue.on("dequeue", () => { | ||
dequeued++; | ||
wg.done(); | ||
}); | ||
|
||
queue.on("enqueue", () => { | ||
queued++; | ||
wg.done(); | ||
}); | ||
|
||
queue.on("dequeue", () => { | ||
dequeuedOnce++; | ||
wg.done(); | ||
}, true); | ||
|
||
queue.on("enqueue", () => { | ||
queuedOnce++; | ||
wg.done(); | ||
}, true); | ||
|
||
queue.enqueue(1); | ||
queue.enqueue(2); | ||
queue.enqueue(3); | ||
|
||
queueMicrotask(() => { | ||
queue.dequeue(); | ||
queue.dequeue(); | ||
queue.dequeue(); | ||
}); | ||
|
||
await wg.wait(); | ||
|
||
assert(queued === 3); | ||
assert(dequeued === 3); | ||
assert(queuedOnce === 1); | ||
assert(dequeuedOnce === 1); | ||
|
||
queue.close() | ||
await queue.onClose(); | ||
}); | ||
|
||
Deno.test("AsyncQueue enqueue full error", async () => { | ||
const queue = asyncQueue<number>({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.