-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
21 lines (18 loc) · 827 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import {
NcpuWorker
} from './worker/index';
export type NCPUOPTION = {ncpuWorker?:NcpuWorker,injectList?:Array<string>,timeout?:number}
const DefaultNCPUOption = {ncpuWorker:new NcpuWorker(),injectList:[],timeout:-1}
export class NCPU {
static getWorker():NcpuWorker {
return new NcpuWorker();
}
static pick(func:Function, {ncpuWorker=new NcpuWorker(),injectList=[],timeout=-1}:NCPUOPTION=DefaultNCPUOption):Function {
return (...params:Array<any>)=>{
return ncpuWorker.run(func, params, {timeout,injectList});
}
}
static run (func:Function,params:Array<any>=[], {ncpuWorker=new NcpuWorker(),injectList=[],timeout=-1}:NCPUOPTION=DefaultNCPUOption):Promise<any> {
return ncpuWorker.run(func, params, {timeout,injectList});
};
}