-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
41 lines (34 loc) · 1.09 KB
/
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
36
37
38
39
40
41
import { behavioralThreadSystem } from "./bthreads.ts"
import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts"
import { run } from "effection"
const TEST_OPTIONS = {
timeout: 5000,
}
Deno.test({
name: "basic event coordination",
...TEST_OPTIONS,
fn: async () => {
const events: string[] = []
await run(() =>
behavioralThreadSystem<string>(function* (thread, sync) {
yield* thread("producer", function* () {
yield sync({ post: ["event1"] })
console.log("posted event1")
yield sync({ post: ["event2"] })
console.log("posted event2")
})
yield* thread("consumer", function* () {
yield sync({ wait: (e) => e === "event1" })
console.log("received event1")
events.push("received event1")
yield sync({ wait: (e) => e === "event2" })
console.log("received event2")
events.push("received event2")
})
console.log("started threads")
})
)
console.log(events)
assertEquals(events, ["received event1", "received event2"])
},
})