Icard/angular-clarity-master(work.../node_modules/piscina/test/messages.ts

20 lines
546 B
TypeScript
Raw Normal View History

2024-07-16 14:55:36 +00:00
import Piscina from '../dist/src';
import { test } from 'tap';
import { resolve } from 'path';
import { once } from 'events';
test('Pool receive message from workers', async ({ equal }) => {
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js')
});
const messagePromise = once(pool, 'message');
const taskResult = pool.runTask(`
require('worker_threads').parentPort.postMessage("some message");
42
`);
equal(await taskResult, 42);
equal((await messagePromise)[0], 'some message');
});