()
| 36 | } |
| 37 | |
| 38 | async 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 |
| 62 | process.on('workerMessage', common.mustCallAtLeast(({ port, level }, source) => { |
searching dependent graphs…