Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix undocumented assumptions about the timing of tsfn calls #995

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions test/threadsafe_function/threadsafe_function.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ async function test(binding) {
binding.threadsafe_function[threadStarter](function testCallback(value) {
array.push(value);
if (array.length === quitAfter) {
setImmediate(() => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you could use process.nextTick if you'd like to keep it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know the exact intention of deferring the close of TSFN here. However, tests all passed with or without deferring.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, original TSFN implementation was re-scheduling each call on the next physical UV loop tick (which was terribly slow), so the setImmediate() got a chance to run right after the first invocation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KevinEady @gabrielschulhof any input on using/not using process.nextTick(). I'll plan to land this tomorrow unless I hear from you so that we can get back to green CI.

binding.threadsafe_function.stopThread(common.mustCall(() => {
resolve(array);
}), !!abort);
});
binding.threadsafe_function.stopThread(common.mustCall(() => {
resolve(array);
}), !!abort);
}
}, !!abort, !!launchSecondary, maxQueueSize);
if (threadStarter === 'startThreadNonblocking') {
Expand Down
8 changes: 3 additions & 5 deletions test/typed_threadsafe_function/typed_threadsafe_function.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ async function test(binding) {
binding.typed_threadsafe_function[threadStarter](function testCallback(value) {
array.push(value);
if (array.length === quitAfter) {
setImmediate(() => {
binding.typed_threadsafe_function.stopThread(common.mustCall(() => {
resolve(array);
}), !!abort);
});
binding.typed_threadsafe_function.stopThread(common.mustCall(() => {
resolve(array);
}), !!abort);
}
}, !!abort, !!launchSecondary, maxQueueSize);
if (threadStarter === 'startThreadNonblocking') {
Expand Down