-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod_test.ts
36 lines (32 loc) · 1 KB
/
mod_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { assert, assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
import { Task } from "./mod.ts";
export function timer(ms: number): Task<never, void> {
return new Task((_, resolve) => {
const id = setTimeout(resolve, ms);
return () => clearTimeout(id);
});
}
Deno.test(function cancelTaskTest() {
let cancelled = false;
const task = new Task((_: unknown, __: unknown) => () => {
cancelled = true;
});
const cancel = task.andThen((_) => Task.succeed(2)).fork(
() => assert(false, "Should always succeed"),
() => {}
);
cancel();
assertEquals(cancelled, true, "Expected this to be cancelled");
});
Deno.test(function anotherCancelTaskTest() {
let cancelled = false;
const task = new Task((_: unknown, __: unknown) => () => {
cancelled = true;
});
const cancel = Task.succeed(2).andThen((_) => task).fork(
() => assert(false, "Should always succeed"),
() => {}
);
cancel();
assertEquals(cancelled, true, "Expected this to be cancelled");
});