xref: /third_party/node/test/parallel/test-worker-terminate-timers.js
  • 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// Test that calling .terminate() during a timer callback works fine.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cifor (const fn of ['setTimeout', 'setImmediate', 'setInterval']) {
81cb0ef41Sopenharmony_ci  const worker = new Worker(`
91cb0ef41Sopenharmony_ci  const { parentPort } = require('worker_threads');
101cb0ef41Sopenharmony_ci  ${fn}(() => {
111cb0ef41Sopenharmony_ci    require('worker_threads').parentPort.postMessage({});
121cb0ef41Sopenharmony_ci    while (true);
131cb0ef41Sopenharmony_ci  });`, { eval: true });
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  worker.on('message', common.mustCallAtLeast(() => {
161cb0ef41Sopenharmony_ci    worker.terminate();
171cb0ef41Sopenharmony_ci  }));
181cb0ef41Sopenharmony_ci}
19

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