xref: /third_party/node/test/parallel/test-worker-nexttick-terminate.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// Checks that terminating in the middle of `process.nextTick()` does not
61cb0ef41Sopenharmony_ci// Crash the process.
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst w = new Worker(`
91cb0ef41Sopenharmony_cirequire('worker_threads').parentPort.postMessage('0');
101cb0ef41Sopenharmony_ciprocess.nextTick(() => {
111cb0ef41Sopenharmony_ci  while(1);
121cb0ef41Sopenharmony_ci});
131cb0ef41Sopenharmony_ci`, { eval: true });
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// Test deprecation of .terminate() with callback.
161cb0ef41Sopenharmony_cicommon.expectWarning(
171cb0ef41Sopenharmony_ci  'DeprecationWarning',
181cb0ef41Sopenharmony_ci  'Passing a callback to worker.terminate() is deprecated. ' +
191cb0ef41Sopenharmony_ci  'It returns a Promise instead.', 'DEP0132');
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciw.on('message', common.mustCall(() => {
221cb0ef41Sopenharmony_ci  setTimeout(() => {
231cb0ef41Sopenharmony_ci    w.terminate(common.mustCall()).then(common.mustCall());
241cb0ef41Sopenharmony_ci  }, 1);
251cb0ef41Sopenharmony_ci}));
26

Indexes created Thu Nov 07 10:32:03 CST 2024