-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test49.ts
81 lines (63 loc) 路 2.19 KB
/
test49.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { Evt, Handler, Ctx } from "../lib/index.ts";
import { assert } from "https://deno.land/x/tsafe@v1.1.3/assert.ts";
import { getPromiseAssertionApi } from "../tools/testing/index.ts";
import { sameFactory } from "../tools/inDepth/index.ts";
import { getHandlerPr } from "./getHandlerPr.ts";
const { same } = sameFactory({ "takeIntoAccountArraysOrdering": false });
const { mustResolve } = getPromiseAssertionApi();
const evtText = new Evt<string>();
const evtAge = new Evt<number>();
const ctx = Evt.newCtx();
const prText = getHandlerPr(evtText,()=> evtText.attach(ctx, () => assert(false)));
const prAge = getHandlerPr(evtAge, ()=> evtAge.attach(ctx, () => assert(false)));
const handlers_ = [
...(evtText.getHandlers() as Handler<string, any, Ctx<any>>[]).map(handler => ({ handler, "evt": evtText })),
...(evtAge.getHandlers() as Handler<string, any, Ctx<any>>[]).map(handler => ({ handler, "evt": evtAge }))
];
mustResolve({
"promise":
getHandlerPr(
ctx.evtDoneOrAborted,
() =>
ctx.evtDoneOrAborted.attachOnce(
({ handlers }) => assert(same(
handlers,
handlers_
))
))
});
mustResolve({
"promise": getHandlerPr(
evtAge.evtDetach,
()=> evtAge.evtDetach.attachOnce(handler => assert(handler.ctx === ctx))
),
"delay": 0
});
const prTest = Promise.all([
mustResolve({
"promise": ctx.evtDetach.waitFor(
({ handler, evt }) => (
evt === evtText &&
handler.ctx === ctx &&
handler.timeout === undefined &&
handler.promise === prText
)
)
}),
mustResolve({
"promise": ctx.evtDetach.waitFor(
({ handler, evt }) => (
evt === evtAge &&
handler.ctx === ctx &&
handler.timeout === undefined &&
handler.promise === prAge
)
)
})
]);
ctx.done();
assert(evtText.getHandlers().length === 0);
assert(evtAge.getHandlers().length === 0);
evtText.post("nothing");
evtAge.post(0);
prTest.then(() => console.log("PASS"));