Skip to content

Commit

Permalink
Reject promise on failure of spawn process (sclang/scsynth)
Browse files Browse the repository at this point in the history
  • Loading branch information
crucialfelix committed Jun 27, 2016
1 parent 3747f47 commit fd826a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/lang/__tests__/sclang-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ describe('sclang', function() {
// mock spawn to return an event emitter
it('should spawnProcess', function() {
var sclang = new SCLang();
spyOn(sclang, '_spawnProcess');
spyOn(sclang, '_spawnProcess').and.returnValue({
pid: 1
});
spyOn(sclang, 'installListeners');
var promise = sclang.spawnProcess('/tmp/fake/path', {});
expect(promise).toBeTruthy();
Expand Down
4 changes: 4 additions & 0 deletions src/lang/sclang.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ export class SCLang extends EventEmitter {
spawnProcess(execPath, commandLineOptions) {
return new Promise((resolve, reject) => {
var done = false;

this.process = this._spawnProcess(execPath, this.args(commandLineOptions));
if (!this.process.pid) {
reject(new Error(`Failed to spawn process ${execPath}`));
}

var bootListener = (state) => {
if (state === STATES.READY) {
Expand Down
13 changes: 12 additions & 1 deletion src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ export class Server extends EventEmitter {
return new Promise((resolve, reject) => {
this.isRunning = false;

this._spawnProcess();
try {
this._spawnProcess();
} catch (e) {
reject(e);
}

this._serverObservers.stdout = Observable.fromEvent(this.process.stdout, 'data', (data) => String(data));
this._serverObservers.stdout.subscribe((e) => this.stdout.onNext(e));
Expand Down Expand Up @@ -223,6 +227,13 @@ export class Server extends EventEmitter {
detached: false
}
});

if (!this.process.pid) {
let error = `Failed to boot ${execPath}`;
this.processEvents.onError(error);
throw new Error(error);
}

this.processEvents.onNext('pid: ' + this.process.pid);

// when this parent process dies, kill child process
Expand Down

0 comments on commit fd826a5

Please sign in to comment.