Skip to content

Commit

Permalink
Storing the destruction error to return it once destruction happened.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheidegger committed Apr 18, 2019
1 parent 91bea98 commit 5b9d41a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cb.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,19 @@ class BashProcess extends ChildProcess {
args: ['bash', '-i', '--noprofile', `${__dirname}${sep}index.sh`],
envPairs
})
this._destruct = once(() => {
this.destructed = true
this._destruct = once((err) => {
this.destructed = err || new Error('Closed.')
destruct()
})
this.on('close', this._destruct)
this.lock = createLockCb()
this._toggleTracker(false)
this.lock(unlock => collectErrOut(this, (err, errPath) => {
if (err) {
this._destruct()
this._destruct(Object.assign(new Error(`Couldn't receive error file`), {
code: err.code,
cause: err
}))
return unlock(err)
}
this.errPath = errPath
Expand All @@ -147,6 +150,9 @@ class BashProcess extends ChildProcess {
}
exec (cmd, encoding, timeout, cb) {
return this.lock(unlock => {
if (this.destructed) {
return unlock(this.destructed)
}
this._setCurrent(unlock, encoding, timeout)
this.stdin.write(`${cmd}\n`)
}, cb)
Expand All @@ -165,7 +171,7 @@ class BashProcess extends ChildProcess {
this._toggleTracker(false)
track(this, this.errPath, timeout, (err, result) => {
if (err) {
this._destruct()
this._destruct(err)
return unlock(err, null, null)
}
this._toggleTracker(true)
Expand Down

0 comments on commit 5b9d41a

Please sign in to comment.