8000 Changes related to worker.terminate() contract changed · HowProgrammingWorks/Threads@05f17e7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 05f17e7

Browse files
committed
Changes related to worker.terminate() contract changed
After node.js v12.5.0 `worker.terminate()` have no callback and returns Promise
1 parent 05b9993 commit 05f17e7

File tree

5 files changed

+11
-19
lines changed

5 files changed

+11
-19
lines changed

JavaScript/2-master.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ worker.on('exit', code => {
1818
console.dir({ code });
1919
});
2020

21-
setTimeout(() => {
22-
worker.terminate((err, code) => {
23-
console.dir({ err, code });
24-
});
21+
setTimeout(async () => {
22+
await worker.terminate();
23+
console.log('Terminated');
2524
}, 1000);

JavaScript/2-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ threads.parentPort.on('message', data => {
88
console.dir({ data });
99
});
1010

11-
//process.exit(0);
11+
process.exit(0);

JavaScript/3-server.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ worker.on('message', msg => {
1111
}
1212
});
1313

14-
process.on('SIGINT', () => {
15-
worker.terminate(() => {
16-
console.log('HTTP Server Stopped');
17-
});
14+
process.on('SIGINT', async () => {
15+
await worker.terminate();
16+
console.log('HTTP Server Stopped');
1817
});

JavaScript/4-share.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,3 @@ worker.on('message', msg => {
1313
console.dir({ value: array[0] });
1414
}
1515
});
16-
17-
process.on('SIGINT', () => {
18-
worker.terminate(() => {
19-
console.log('Bye');
20-
});
21-
});

JavaScript/5-share.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ setInterval(() => {
1111
console.dir(buffer);
1212
}, 100);
1313

14-
process.on('SIGINT', () => {
15-
worker.terminate(() => {
16-
console.log('Bye');
17-
});
14+
process.on('SIGINT', async () => {
15+
await worker.terminate();
16+
console.log('Bye');
17+
process.exit(0);
1818
});

0 commit comments

Comments
 (0)
0