@travetto/exec
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -8,2 +8,3 @@ { | ||
"@travetto/base": "0.x.x", | ||
"@travetto/pool": "0.x.x", | ||
"@types/cross-spawn": "^6.0.0", | ||
@@ -19,3 +20,3 @@ "cross-spawn": "^6.0.5" | ||
}, | ||
"version": "0.0.5" | ||
"version": "0.0.6" | ||
} |
@@ -42,3 +42,4 @@ import * as child_process from 'child_process'; | ||
} | ||
super.kill(); | ||
} | ||
} |
@@ -98,4 +98,10 @@ import { CommonProcess, ExecutionEvent } from './types'; | ||
kill() { | ||
this.clean(); | ||
delete this._proc; | ||
} | ||
get pid() { | ||
return this._proc && this._proc.pid; | ||
} | ||
clean() { | ||
@@ -102,0 +108,0 @@ if (this._proc) { |
@@ -18,2 +18,3 @@ import * as child_process from 'child_process'; | ||
export interface CommonProcess { | ||
pid: number; | ||
send?(message: any, sendHandle?: any): void; | ||
@@ -20,0 +21,0 @@ removeListener(name: string, f: Function): void; |
@@ -1,29 +0,33 @@ | ||
import { ChildExecution, ExecutionPool } from '../src'; | ||
import { ChildExecution, ExecutionPool, ArrayDataSource, IteratorDataSource } from '../src'; | ||
const pool = new ExecutionPool<ChildExecution>({ | ||
count: 1, | ||
create() { | ||
const child = new ChildExecution(`${__dirname}/index.js`, true, { | ||
env: { SRC: './simple.child' } | ||
}); | ||
child.init(); | ||
(child as any)['ready'] = child.listenOnce('ready'); | ||
return child; | ||
const pool = new ExecutionPool<ChildExecution>(async () => { | ||
console.log('Initializing child'); | ||
const child = new ChildExecution(`${__dirname}/index.js`, true, { | ||
env: { SRC: './simple.child' } | ||
}); | ||
child.init(); | ||
await child.listenOnce('ready'); | ||
console.log('Child ready'); | ||
return child; | ||
}, | ||
async init(child: ChildExecution) { | ||
await (child as any)['ready']; | ||
return child; | ||
}, | ||
async exec(inp: string, child: ChildExecution) { | ||
const wait = child.listenOnce('response'); | ||
child.send('request', { data: inp }); | ||
const res = await wait; | ||
console.log('Sent', inp, 'Received', res); | ||
}, { max: 1 }); | ||
pool.process( | ||
// new ArrayDataSource(['a', 'b', 'c', 'd', 'e', 'f', 'g']), | ||
new IteratorDataSource(function* () { | ||
for (let i = 0; i < 10; i++) { | ||
yield `${i}-`; | ||
} | ||
}), | ||
async (i: string, exe: ChildExecution) => { | ||
const res = exe.listenOnce('response'); | ||
exe.send('request', { data: i }); | ||
const { data } = await res; | ||
console.log('Sent', i, 'Received', data); | ||
await new Promise(r => setTimeout(r, 1000)); | ||
} | ||
}); | ||
pool.process(['a', 'b', 'c', 'd', 'e', 'f', 'g']).then(() => { | ||
).then(async () => { | ||
console.log('DONE!'); | ||
pool.shutdown(); | ||
await pool.shutdown(); | ||
process.exit(0); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13171
21
440
0
4
+ Added@travetto/pool@0.x.x
+ Added@travetto/base@0.3.18(transitive)
+ Added@travetto/pool@0.3.13(transitive)
+ Added@types/generic-pool@3.8.3(transitive)
+ Added@types/node@10.17.60(transitive)
+ Addedgeneric-pool@3.9.0(transitive)
+ Addedstack-chain@2.0.0(transitive)
+ Addedtrace@3.2.0(transitive)