node-worker-threads-pool-ts
Version:
Simple worker threads pool using Node's worker_threads module. Compatible with ES6+ Promise, Typescript, Async/Await.
15 lines (13 loc) • 393 B
text/typescript
const es6FuncReg = /^task[^]*([^]*)[^]*{[^]*}$/;
export function createCode(fn: Function): string {
const strFn = Function.prototype.toString.call(fn);
let expression = "";
if (es6FuncReg.test(strFn)) {
// ES6 style in-object function.
expression = "function " + strFn;
} else {
// ES5 function or arrow function.
expression = strFn;
}
return `(${expression})`;
}