xref: /third_party/node/test/parallel/test-worker-message-port-message-port-transferring.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 assert = require('assert');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst { MessageChannel } = require('worker_threads');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci{
81cb0ef41Sopenharmony_ci  const { port1: basePort1, port2: basePort2 } = new MessageChannel();
91cb0ef41Sopenharmony_ci  const {
101cb0ef41Sopenharmony_ci    port1: transferredPort1, port2: transferredPort2
111cb0ef41Sopenharmony_ci  } = new MessageChannel();
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci  basePort1.postMessage({ transferredPort1 }, [ transferredPort1 ]);
141cb0ef41Sopenharmony_ci  basePort2.on('message', common.mustCall(({ transferredPort1 }) => {
151cb0ef41Sopenharmony_ci    transferredPort1.postMessage('foobar');
161cb0ef41Sopenharmony_ci    transferredPort2.on('message', common.mustCall((msg) => {
171cb0ef41Sopenharmony_ci      assert.strictEqual(msg, 'foobar');
181cb0ef41Sopenharmony_ci      transferredPort1.close(common.mustCall());
191cb0ef41Sopenharmony_ci      basePort1.close(common.mustCall());
201cb0ef41Sopenharmony_ci    }));
211cb0ef41Sopenharmony_ci  }));
221cb0ef41Sopenharmony_ci}
23

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