MCPcopy Index your code
hub / github.com/nodejs/node / ping

Function ping

test/parallel/test-worker-messaging.js:38–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36}
37
38async function ping() {
39 let target;
40 do {
41 target = mainThread + Math.floor(Math.random() * MAX_THREAD);
42 } while (target === threadId);
43
44 const { port1, port2 } = new MessageChannel();
45 await postMessageToThread(target, { level, port: port2 }, [port2]);
46
47 port1.on('message', common.mustCall(function(message) {
48 assert.deepStrictEqual(message, { message: 'pong', source: target, destination: threadId });
49 port1.close();
50
51 if (level === 0) {
52 completed.dec();
53 } else {
54 channel.postMessage('end');
55 }
56 }));
57
58 port1.postMessage({ message: 'ping', source: threadId, destination: target });
59}
60
61// Do not use mustCall here as the thread might not receive any connection request
62process.on('workerMessage', common.mustCallAtLeast(({ port, level }, source) => {

Callers 1

testFunction · 0.70

Calls 6

postMessageToThreadFunction · 0.85
randomMethod · 0.80
decMethod · 0.80
closeMethod · 0.65
onMethod · 0.45
postMessageMethod · 0.45

Tested by 1

testFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…