effection-race-not-caught.diff

on erock's pastes | raw

expires: 22 May, 2024

 1diff --git a/test/race.test.ts b/test/race.test.ts
 2index a3a6c3b..71cf7b7 100644
 3--- a/test/race.test.ts
 4+++ b/test/race.test.ts
 5@@ -9,9 +9,30 @@ import {
 6   syncResolve,
 7 } from "./suite.ts";
 8 
 9-import { call, type Operation, race, run } from "../mod.ts";
10+import { call, type Operation, race, run, sleep } from "../mod.ts";
11 
12 describe("race()", () => {
13+  it("ability to catch cancel", async () => {
14+    let caught = false;
15+    let result = run(() =>
16+      race([
17+        function*(): Operation<unknown> {
18+          try {
19+            yield* sleep(10);
20+            return "baz";
21+          } catch (err) {
22+            console.log(err);
23+            caught = true;
24+          }
25+        }(),
26+        asyncResolve(5, "bar"),
27+      ])
28+    );
29+
30+    await expect(result).resolves.toEqual("bar");
31+    expect(caught).toBeTruthy();
32+  });
33+
34   it("resolves when one of the given operations resolves asynchronously first", async () => {
35     let result = run(() =>
36       race([