-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-diagnostics-channel-tracing-channel-iterator-async-next.js
More file actions
54 lines (44 loc) · 1.52 KB
/
test-diagnostics-channel-tracing-channel-iterator-async-next.js
File metadata and controls
54 lines (44 loc) · 1.52 KB
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
'use strict';
const common = require('../common');
const dc = require('diagnostics_channel');
const assert = require('assert');
const channel = dc.tracingChannel('test');
const nextChannel = dc.tracingChannel('test:next');
const expectedResult = { foo: 'bar' };
const input = { foo: 'bar' };
const thisArg = { baz: 'buz' };
function check(found) {
assert.deepStrictEqual(found, input);
}
function checkNextAsync(found) {
check(found);
assert.strictEqual(found.error, undefined);
assert.deepStrictEqual(found.result, { value: expectedResult, done: false });
}
// Async function* returns an AsyncGenerator synchronously, so no asyncStart/asyncEnd
// for the fn call itself
const handlers = {
start: common.mustCall(check),
end: common.mustCall(check),
asyncStart: common.mustNotCall(),
asyncEnd: common.mustNotCall(),
error: common.mustNotCall(),
};
// next() on an AsyncGenerator returns a Promise
const nextHandlers = {
start: common.mustCall(check),
end: common.mustCall(check),
asyncStart: common.mustCall(checkNextAsync),
asyncEnd: common.mustCall(checkNextAsync),
error: common.mustNotCall(),
};
channel.subscribe(handlers);
nextChannel.subscribe(nextHandlers);
const iter = channel.traceIterator(common.mustCall(async function*(value) {
assert.deepStrictEqual(this, thisArg);
yield value;
}), input, thisArg, expectedResult);
// next() returns a Promise since iter is an AsyncGenerator
iter.next().then(common.mustCall((result) => {
assert.deepStrictEqual(result, { value: expectedResult, done: false });
}));