sync-request icon indicating copy to clipboard operation
sync-request copied to clipboard

sync-request import blocking in worker_threads

Open cyoyo-geek opened this issue 5 years ago • 0 comments

Run the code multiple times, the program will occasionally get stuck in require().

Operating environment: node version: v10.16.3 node-worker-threads-pool: 1.4.3 sync-request: 6.1.0


'use strict';
const { StaticPool } = require("node-worker-threads-pool");
async function task(i) {
	require('sync-request'); // Problem code causes the program to occasionally get stuck
	console.log(i);   
	return
}

async function taskStaticPool() {
	const pool = new StaticPool({
		size: 5,
		task: task,
	});

	var execArr = [];
	for (let j = 0; j < 100; j++) {
		execArr.push(pool.exec(j));
	}
	await Promise.all(execArr);
	pool.destroy();
}
taskStaticPool()

cyoyo-geek avatar Nov 27 '20 07:11 cyoyo-geek