Skip to content

Commit

Permalink
Merge pull request #7 from thefrontside/cl/task-buffer-tests
Browse files Browse the repository at this point in the history
✅ Add test for draining a task buffer
  • Loading branch information
taras authored Sep 18, 2024
2 parents 68508d2 + 69719e1 commit e9bdd37
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions task-buffer/task-buffer.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { run, sleep, spawn, suspend, type Task } from "effection";
import { run, sleep, spawn, type Task } from "effection";
import { describe, it } from "bdd";
import { expect } from "expect";
import { useTaskBuffer } from "./task-buffer.ts";
Expand Down Expand Up @@ -27,9 +27,21 @@ describe("TaskBuffer", () => {
});
});

it("spawns new tasks when space becomes available", () => {
});

it("allows to wait until there are now more tasks", () => {
it("allows to wait until buffer is drained", async () => {
let finished = 0;
await run(function*() {
let buffer = yield* useTaskBuffer(5);
for (let i = 0; i < 3; i++) {
yield* buffer.spawn(function*() {
yield* sleep(10);
finished++;
});
}
expect(finished).toEqual(0);

yield* buffer;

expect(finished).toEqual(3);
});
});
});

0 comments on commit e9bdd37

Please sign in to comment.