Skip to content

Commit

Permalink
Implement disconnect.
Browse files Browse the repository at this point in the history
  • Loading branch information
flatheadmill committed Jun 20, 2016
1 parent 98c41ea commit adc46ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 5 additions & 3 deletions program.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ Program.prototype.once = function (event, listener) {
}

Program.prototype.disconnect = function () {
if (this._process.connected) {
this._process.disconnect()
}
this._process.disconnect()
}

Program.prototype.__defineSetter__('exitCode', function (exitCode) {
Expand All @@ -155,6 +153,10 @@ Program.prototype.__defineGetter__('exitCode', function () {
return this._process.exitCode
})

Program.prototype.__defineGetter__('connected', function () {
return this._process.connected
})

Program.prototype._hook = function (event) {
if (!this._hooked[event]) {
this._process.on(event, function () {
Expand Down
12 changes: 11 additions & 1 deletion t/program.t.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('proof')(39, require('cadence')(prove))
require('proof')(42, require('cadence')(prove))

/*
___ usage ___ en_US ___
Expand Down Expand Up @@ -36,6 +36,16 @@ function prove (async, assert) {
if (error) throw error
assert(io.events.exitCode, 1, 'exit non-zero')
})
createProgram(__filename, {}, [], io = {
events: { connected: true, disconnect: function () { this.connected = false } }
}, cadence(function (async, program) {
assert(program.connected, 'connected')
program.disconnect()
assert(!program.connected, 'not connected')
}), function (error) {
if (error) throw error
assert(!io.events.connected, 'exit not connected')
})
createProgram(__filename, {}, [], {}, cadence(function (async, program) {
throw new Error('raw')
}), function (error) {
Expand Down

0 comments on commit adc46ea

Please sign in to comment.