Skip to content

Commit 46b889a

Browse files
committed
fix lint issues
1 parent 35cf970 commit 46b889a

5 files changed

+25
-26
lines changed

lib/diagnostics_channel.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ function tracingChannelFrom(nameOrChannels, name) {
281281
}
282282

283283
class TracingChannel {
284-
#nextChannel
284+
#nextChannel;
285285

286286
constructor(nameOrChannels) {
287287
for (let i = 0; i < traceEvents.length; ++i) {
@@ -438,17 +438,13 @@ class TracingChannel {
438438

439439
const { start, end, asyncStart, asyncEnd, error } = this;
440440

441-
if (!this.#nextChannel) {
442-
this.#nextChannel = tracingChannel({
443-
start: channel(start.name.slice(0, -6) + ':next:start'),
444-
end: channel(end.name.slice(0, -4) + ':next:end'),
445-
asyncStart: channel(asyncStart.name.slice(0, -11) + ':next:asyncStart'),
446-
asyncEnd: channel(asyncEnd.name.slice(0, -9) + ':next:asyncEnd'),
447-
error: channel(error.name.slice(0, -6) + ':next:error'),
448-
});
449-
}
450-
451-
const nextChannel = this.#nextChannel;
441+
const nextChannel = this.#nextChannel ||= tracingChannel({
442+
start: channel(start.name.slice(0, -6) + ':next:start'),
443+
end: channel(end.name.slice(0, -4) + ':next:end'),
444+
asyncStart: channel(asyncStart.name.slice(0, -11) + ':next:asyncStart'),
445+
asyncEnd: channel(asyncEnd.name.slice(0, -9) + ':next:asyncEnd'),
446+
error: channel(error.name.slice(0, -6) + ':next:error'),
447+
});
452448

453449
const wrapIter = (iter) => {
454450
const { next: iterNext, return: iterReturn, throw: iterThrow } = iter;
@@ -465,9 +461,9 @@ class TracingChannel {
465461

466462
const result = this.#traceMaybePromise(fn, context, thisArg, ...args);
467463

468-
return result instanceof Promise
469-
? PromisePrototypeThen(result, wrapIter)
470-
: wrapIter(result);
464+
return result instanceof Promise ?
465+
PromisePrototypeThen(result, wrapIter) :
466+
wrapIter(result);
471467
}
472468

473469
#traceMaybePromise(fn, context = {}, thisArg, ...args) {
@@ -499,8 +495,8 @@ class TracingChannel {
499495
const result = ReflectApply(fn, thisArg, args);
500496
// TODO: Should tracePromise just always do this?
501497
if (!(result instanceof Promise)) {
502-
context.result = result
503-
return result
498+
context.result = result;
499+
return result;
504500
}
505501
return PromisePrototypeThen(result, resolve, reject);
506502
} catch (err) {

test/parallel/test-diagnostics-channel-tracing-channel-iterator-async-next.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function checkNextAsync(found) {
2121
assert.deepStrictEqual(found.result, { value: expectedResult, done: false });
2222
}
2323

24-
// async function* returns an AsyncGenerator synchronously, so no asyncStart/asyncEnd
24+
// Async function* returns an AsyncGenerator synchronously, so no asyncStart/asyncEnd
2525
// for the fn call itself
2626
const handlers = {
2727
start: common.mustCall(check),

test/parallel/test-diagnostics-channel-tracing-channel-iterator-error.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ const handlers = {
2929
error: common.mustNotCall(),
3030
};
3131

32-
// next() and throw() each produce one error
32+
// iter1: next() success + next() throws = start×2, end×2, error×1
33+
// iter2: throw() throws = start×1, end×1, error×1
3334
const nextHandlers = {
34-
start: common.mustCall(check, 2),
35-
end: common.mustCall(check, 2),
35+
start: common.mustCall(check, 3),
36+
end: common.mustCall(check, 3),
3637
asyncStart: common.mustNotCall(),
3738
asyncEnd: common.mustNotCall(),
3839
error: common.mustCall(checkError, 2),
@@ -41,12 +42,14 @@ const nextHandlers = {
4142
channel.subscribe(handlers);
4243
nextChannel.subscribe(nextHandlers);
4344

44-
// Test next(): generator throws on first next() call
45+
// Test next(): generator throws after the first yield
4546
const iter1 = channel.traceIterator(common.mustCall(function*() {
4647
assert.deepStrictEqual(this, thisArg);
48+
yield 1;
4749
throw expectedError;
4850
}), input, thisArg);
4951

52+
assert.deepStrictEqual(iter1.next(), { value: 1, done: false });
5053
assert.throws(() => iter1.next(), expectedError);
5154

5255
// Test throw(): propagates error through the iterator

test/parallel/test-diagnostics-channel-tracing-channel-iterator-promise-async-next.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function checkNextAsync(found) {
3333
assert.deepStrictEqual(found.result, { value: expectedResult, done: false });
3434
}
3535

36-
// async fn returns a Promise, so main channel fires asyncStart/asyncEnd
36+
// Async fn returns a Promise, so main channel fires asyncStart/asyncEnd
3737
const handlers = {
3838
start: common.mustCall(check),
3939
end: common.mustCall(check),
@@ -54,7 +54,7 @@ const nextHandlers = {
5454
channel.subscribe(handlers);
5555
nextChannel.subscribe(nextHandlers);
5656

57-
// fn is async: returns a Promise resolving to an AsyncGenerator
57+
// Fn is async: returns a Promise resolving to an AsyncGenerator
5858
// traceIterator returns a Promise resolving to the wrapped AsyncGenerator
5959
channel.traceIterator(common.mustCall(async function() {
6060
assert.deepStrictEqual(this, thisArg);

test/parallel/test-diagnostics-channel-tracing-channel-iterator-promise.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function checkAsync(found) {
2424
assert.strictEqual(found.result, syncIter);
2525
}
2626

27-
// async fn returns a Promise, so main channel fires asyncStart/asyncEnd
27+
// Async fn returns a Promise, so main channel fires asyncStart/asyncEnd
2828
const handlers = {
2929
start: common.mustCall(check),
3030
end: common.mustCall(check),
@@ -45,7 +45,7 @@ const nextHandlers = {
4545
channel.subscribe(handlers);
4646
nextChannel.subscribe(nextHandlers);
4747

48-
// fn is async: returns a Promise resolving to a sync iterator
48+
// Fn is async: returns a Promise resolving to a sync iterator
4949
// traceIterator returns a Promise resolving to the wrapped iterator
5050
channel.traceIterator(common.mustCall(async function() {
5151
assert.deepStrictEqual(this, thisArg);

0 commit comments

Comments
 (0)