worker-parrot-party
Version:
Parrot party for everyone
60 lines • 2.62 kB
TypeScript
/**
* Class in charge of managing the worker scripts. It is target to create the TS file to use for the workers and
* compile it, since Workers do not support Typescript files.
*/
export declare class ScriptManager {
private readonly _outDir;
private readonly _basePath;
constructor(_outDir: string, _basePath: string);
/**
* This function will compile the typescript file and create a plain JS file, that will be
* used as a worker script.
* @param fileName Name of the file to compile
* @param filePath Path where the file is located
*/
private _compileScriptFile;
/**
* This function will delete the previous script file, if it exists.
* We do this in order to ensure that we only have a single execution script per pool of workers.
* @param filePath Path to the script file
*/
private _deletePreviosScript;
/**
* Function to determine the name of the task function.
* @param task
* @returns task name if exists otherwise returns 'anonymous'
*/
private _determineTaskFunctionName;
/**
* This function transforms a given task function into a worker script.
*
* NOTE: In order to avoid compilation error warnings due to nature of typescipt, we use the flag
* @ts-nocheck to disable the type checking.
*
* reference: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html
* @param task
* @returns String representation of the task to be used by the worker functions
*/
private _createWorkerScriptString;
/**
* This function converts a task function into a TS file, that will be used as a worker script. In addition,
* deletes the previously created TS file and compiles a new version to be used by the worker threads.
*
* NOTE: When calling the function toString() function, we receieve a JS representation of the function that uses
* ___awaitor.
*
* References:
* - https://medium.com/@joshuakgoldberg/hacking-typescripts-async-await-awaiter-for-jquery-2-s-promises-60612e293c4b
* - https://github.com/SUCHMOKUO/node-worker-threads-pool/blob/f2220030a27e5b8333e12fb9edafeb29602a484b/src/utils.ts
*
* @param task
* @returns full qualified path of the JS worker script.
*/
createAndCompileExecutionScript(task: Function, handlers?: Array<Function>, libs?: Array<{
name: string;
importDeclaration: string;
}>): Promise<string>;
private listFolderFiles;
private getFullPathOfCompiledFile;
}
//# sourceMappingURL=ScriptManager.d.ts.map