You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

21 lines
608 B

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import { once } from 'node:events';
import Piscina from '..';
test('Pool receive message from workers', async () => {
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js')
});
const messagePromise = once(pool, 'message');
const taskResult = pool.run(`
require('worker_threads').parentPort.postMessage("some message");
42
`);
assert.strictEqual(await taskResult, 42);
assert.strictEqual((await messagePromise)[0], 'some message');
});