8 Commits

Author SHA1 Message Date
8fbd9c0b51 1.0.9 2017-03-04 19:20:03 +01:00
1850f7d132 add argvArgs to simpleThread 2017-03-04 19:20:00 +01:00
e0dffad3f2 1.0.8 2017-03-04 12:24:34 +01:00
241880f2b0 add forkOptions 2017-03-04 12:24:32 +01:00
9d33a5df53 1.0.7 2017-03-04 12:05:57 +01:00
57ddf4c45d improve typings 2017-03-04 12:05:53 +01:00
1329513543 1.0.6 2017-03-04 11:59:58 +01:00
e1acfd03e6 ThreadSimple is now returning a Promise 2017-03-04 11:59:56 +01:00
4 changed files with 24 additions and 11 deletions

View File

@ -2,6 +2,8 @@ import * as childProcess from 'child_process';
export declare class ThreadSimple { export declare class ThreadSimple {
workerPath: string; workerPath: string;
threadChildProcess: childProcess.ChildProcess; threadChildProcess: childProcess.ChildProcess;
constructor(filePathArg: string); forkOptions: childProcess.ForkOptions;
run(): childProcess.ChildProcess; argvArgs: string[];
constructor(filePathArg: string, argvArgs?: string[], forkOptionsArg?: childProcess.ForkOptions);
run(): Promise<childProcess.ChildProcess>;
} }

View File

@ -1,13 +1,17 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartipc.plugins"); const plugins = require("./smartipc.plugins");
const smartq = require("smartq");
const childProcess = require("child_process"); const childProcess = require("child_process");
const smartipc_classes_thread_1 = require("./smartipc.classes.thread"); const smartipc_classes_thread_1 = require("./smartipc.classes.thread");
class ThreadSimple { class ThreadSimple {
constructor(filePathArg) { constructor(filePathArg, argvArgs = [], forkOptionsArg = {}) {
this.workerPath = filePathArg; this.workerPath = filePathArg;
this.forkOptions = forkOptionsArg;
this.argvArgs = argvArgs;
} }
run() { run() {
let done = smartq.defer();
let forkPath = (() => { let forkPath = (() => {
if (smartipc_classes_thread_1.workerBasePath) { if (smartipc_classes_thread_1.workerBasePath) {
return plugins.path.join(smartipc_classes_thread_1.workerBasePath, this.workerPath); return plugins.path.join(smartipc_classes_thread_1.workerBasePath, this.workerPath);
@ -16,9 +20,10 @@ class ThreadSimple {
return this.workerPath; return this.workerPath;
} }
})(); })();
this.threadChildProcess = childProcess.fork(forkPath); this.threadChildProcess = childProcess.fork(forkPath, this.argvArgs, this.forkOptions);
return this.threadChildProcess; done.resolve(this.threadChildProcess);
return done.promise;
} }
} }
exports.ThreadSimple = ThreadSimple; exports.ThreadSimple = ThreadSimple;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy50aHJlYWRzaW1wbGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGlwYy5jbGFzc2VzLnRocmVhZHNpbXBsZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLDhDQUE2QztBQUU3Qyw4Q0FBNkM7QUFFN0MsdUVBQTBEO0FBRTFEO0lBR0UsWUFBYSxXQUFtQjtRQUM5QixJQUFJLENBQUMsVUFBVSxHQUFHLFdBQVcsQ0FBQTtJQUMvQixDQUFDO0lBRUQsR0FBRztRQUNELElBQUksUUFBUSxHQUFHLENBQUM7WUFDZCxFQUFFLENBQUMsQ0FBQyx3Q0FBYyxDQUFDLENBQUMsQ0FBQztnQkFDbkIsTUFBTSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLHdDQUFjLEVBQUUsSUFBSSxDQUFDLFVBQVUsQ0FBQyxDQUFBO1lBQzNELENBQUM7WUFBQyxJQUFJLENBQUMsQ0FBQztnQkFDTixNQUFNLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQTtZQUN4QixDQUFDO1FBQ0gsQ0FBQyxDQUFDLEVBQUUsQ0FBQTtRQUNKLElBQUksQ0FBQyxrQkFBa0IsR0FBRyxZQUFZLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxDQUFBO1FBQ3JELE1BQU0sQ0FBQyxJQUFJLENBQUMsa0J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RUFBRSxJQUFJLENBQUMsUUFBUSxFQUFFLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQTtRQUN0RixJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxDQUFBO1FBQ3JDLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3JCLENBQUM7Q0FDRjtBQXhCRCxvQ0F3QkMifQ==

View File

@ -1,6 +1,6 @@
{ {
"name": "smartipc", "name": "smartipc",
"version": "1.0.5", "version": "1.0.9",
"description": "smart subprocess handling", "description": "smart subprocess handling",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",

View File

@ -1,5 +1,5 @@
import * as plugins from './smartipc.plugins' import * as plugins from './smartipc.plugins'
import * as q from 'smartq' import * as smartq from 'smartq'
import * as childProcess from 'child_process' import * as childProcess from 'child_process'
import { workerBasePath } from './smartipc.classes.thread' import { workerBasePath } from './smartipc.classes.thread'
@ -7,11 +7,16 @@ import { workerBasePath } from './smartipc.classes.thread'
export class ThreadSimple { export class ThreadSimple {
workerPath: string workerPath: string
threadChildProcess: childProcess.ChildProcess threadChildProcess: childProcess.ChildProcess
constructor (filePathArg: string) { forkOptions: childProcess.ForkOptions
argvArgs: string[]
constructor (filePathArg: string, argvArgs: string[] = [], forkOptionsArg: childProcess.ForkOptions = {}) {
this.workerPath = filePathArg this.workerPath = filePathArg
this.forkOptions = forkOptionsArg
this.argvArgs = argvArgs
} }
run () { run () {
let done = smartq.defer<childProcess.ChildProcess>()
let forkPath = (() => { let forkPath = (() => {
if (workerBasePath) { if (workerBasePath) {
return plugins.path.join(workerBasePath, this.workerPath) return plugins.path.join(workerBasePath, this.workerPath)
@ -19,7 +24,8 @@ export class ThreadSimple {
return this.workerPath return this.workerPath
} }
})() })()
this.threadChildProcess = childProcess.fork(forkPath) this.threadChildProcess = childProcess.fork(forkPath, this.argvArgs, this.forkOptions)
return this.threadChildProcess done.resolve(this.threadChildProcess)
return done.promise
} }
} }