(
prog: string, args: readonly string[] = [],
spawnOpts: childProcess.SpawnOptions = {}, cb: (line: string) => boolean = null)
| 805 | } |
| 806 | |
| 807 | public startWithProgram( |
| 808 | prog: string, args: readonly string[] = [], |
| 809 | spawnOpts: childProcess.SpawnOptions = {}, cb: (line: string) => boolean = null): Promise<boolean> { |
| 810 | if (this.promise) { throw new Error('SpawnLineReader: can\'t reuse this object'); } |
| 811 | this.callback = cb; |
| 812 | this.promise = new Promise<boolean>((resolve) => { |
| 813 | try { |
| 814 | const child = childProcess.spawn(prog, args, spawnOpts); |
| 815 | child.on('error', (err) => { |
| 816 | this.emit('error', err); |
| 817 | resolve(false); |
| 818 | }); |
| 819 | child.on('exit', (code: number, signal: string) => { |
| 820 | this.emit('exit', code, signal); |
| 821 | // read-line will resolve. Not us |
| 822 | }); |
| 823 | this.doReadline(child.stdout, resolve); |
| 824 | } |
| 825 | catch (e) { |
| 826 | this.emit('error', e); |
| 827 | } |
| 828 | }); |
| 829 | return this.promise; |
| 830 | } |
| 831 | |
| 832 | public startWithStream(rStream: stream.Readable, cb: (line: string) => boolean = null): Promise<boolean> { |
| 833 | if (this.promise) { throw new Error('SpawnLineReader: can\'t reuse this object'); } |
no test coverage detected