Commit 3611b47
worker: refactor
At the collaborator summit in Berlin, the behaviour of
`worker.terminate()` was discussed.
In particular, switching from a callback-based to a Promise-based API
was suggested. While investigating that possibility later, it was
discovered that `.terminate()` was unintentionally synchronous up
until now (including calling its callback synchronously).
Also, the topic of its stability has been brought up. I have performed
two manual reviews of the native codebase for compatibility with
`.terminate()`, and performed some manual fuzz testing with the test
suite. At this point, bugs with `.terminate()` should, in my opinion,
be treated like bugs in other Node.js features.
(It is possible to make Node.js crash with `.terminate()` by messing
with internals and/or built-in prototype objects, but that is already
the case without `.terminate()` as well.)
This commit:
- Makes `.terminate()` an asynchronous operation.
- Makes `.terminate()` return a `Promise`.
- Runtime-deprecates passing a callback.
- Removes a warning about its stability from the documentation.
- Eliminates an unnecessary extra function from the C++ code.
A possible alternative to returning a `Promise` would be to keep the
method synchronous and just drop the callback. Generally, providing
an asynchronous API does provide us with a bit more flexibility.
Refs: openjs-foundation/summit#141
PR-URL: #28021
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>worker.terminate()
1 parent 83fc10d commit 3611b47Copy full SHA for 3611b47
File tree
Expand file treeCollapse file tree
7 files changed
+50
-23
lines changedOpen diff view settings
Filter options
- doc/api
- lib/internal
- src
- test/parallel
Expand file treeCollapse file tree
7 files changed
+50
-23
lines changedOpen diff view settings
Collapse file
+15Lines changed: 15 additions & 0 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
2477 | 2477 | |
2478 | 2478 | |
2479 | 2479 | |
| 2480 | + |
| 2481 | + |
| 2482 | + |
| 2483 | + |
| 2484 | + |
| 2485 | + |
| 2486 | + |
| 2487 | + |
| 2488 | + |
| 2489 | + |
| 2490 | + |
| 2491 | + |
| 2492 | + |
| 2493 | + |
2480 | 2494 | |
2481 | 2495 | |
2482 | 2496 | |
| ||
2569 | 2583 | |
2570 | 2584 | |
2571 | 2585 | |
| 2586 | + |
2572 | 2587 | |
2573 | 2588 | |
2574 | 2589 | |
|
Collapse file
+13-13Lines changed: 13 additions & 13 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
617 | 617 | |
618 | 618 | |
619 | 619 | |
620 | | - |
| 620 | + |
621 | 621 | |
622 | 622 | |
| 623 | + |
| 624 | + |
| 625 | + |
| 626 | + |
| 627 | + |
| 628 | + |
| 629 | + |
623 | 630 | |
624 | 631 | |
625 | | - |
626 | | - |
627 | | - |
| 632 | + |
628 | 633 | |
629 | 634 | |
630 | | - |
631 | | - |
632 | | - |
633 | | - |
634 | | - |
635 | | - |
636 | | - |
637 | | - |
| 635 | + |
| 636 | + |
638 | 637 | |
639 | 638 | |
640 | 639 | |
| ||
657 | 656 | |
658 | 657 | |
659 | 658 | |
| 659 | + |
660 | 660 | |
661 | 661 | |
662 | 662 | |
| ||
690 | 690 | |
691 | 691 | |
692 | 692 | |
693 | | - |
| 693 | + |
694 | 694 | |
695 | 695 | |
696 | 696 | |
|
Collapse file
+13-1Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
228 | 228 | |
229 | 229 | |
230 | 230 | |
231 | | - |
| 231 | + |
| 232 | + |
| 233 | + |
| 234 | + |
| 235 | + |
232 | 236 | |
| 237 | + |
233 | 238 | |
234 | 239 | |
| 240 | + |
| 241 | + |
| 242 | + |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | + |
235 | 247 | |
236 | 248 | |
237 | 249 | |
|
Collapse file
+1-6Lines changed: 1 addition & 6 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
352 | 352 | |
353 | 353 | |
354 | 354 | |
355 | | - |
356 | 355 | |
357 | | - |
358 | 356 | |
359 | | - |
360 | 357 | |
361 | 358 | |
362 | 359 | |
| ||
370 | 367 | |
371 | 368 | |
372 | 369 | |
373 | | - |
| 370 | + |
374 | 371 | |
375 | 372 | |
376 | 373 | |
| ||
534 | 531 | |
535 | 532 | |
536 | 533 | |
537 | | - |
538 | | - |
539 | 534 | |
540 | 535 | |
541 | 536 | |
|
Collapse file
-1Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | | - |
56 | 55 | |
57 | 56 | |
58 | 57 | |
|
Collapse file
test/parallel/test-worker-dns-terminate.js
Copy file name to clipboardExpand all lines: test/parallel/test-worker-dns-terminate.js+1-1Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
10 | 10 | |
11 | 11 | |
12 | 12 | |
13 | | - |
| 13 | + |
14 | 14 | |
Collapse file
test/parallel/test-worker-nexttick-terminate.js
Copy file name to clipboardExpand all lines: test/parallel/test-worker-nexttick-terminate.js+7-1Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
12 | 12 | |
13 | 13 | |
14 | 14 | |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
15 | 21 | |
16 | 22 | |
17 | | - |
| 23 | + |
18 | 24 | |
19 | 25 | |
0 commit comments