Skip to content

Commit

Permalink
Can call destroy twice
Browse files Browse the repository at this point in the history
  • Loading branch information
dex4er committed Feb 5, 2018
1 parent c927d0f commit 57bfe1f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v3.0.1 2018-02-05

* Can call `destroy` twice.

## v3.0.0 2018-02-04

* New `setEncoding` and `destroy` methods.
Expand Down
12 changes: 8 additions & 4 deletions lib/promise-duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,14 @@ class PromiseDuplex extends PromiseReadable /* and PromiseWritable */ {
}

destroy () {
this.readable.destroy()
delete this.readable
this.writable.destroy()
delete this.writable
if (this.readable) {
this.readable.destroy()
delete this.readable
}
if (this.writable) {
this.writable.destroy()
delete this.writable
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "promise-duplex",
"version": "3.0.0",
"version": "3.0.1",
"description": "Return promise for duplex stream",
"main": "lib/promise-duplex.js",
"typings": "lib/promise-duplex.d.ts",
Expand All @@ -23,8 +23,8 @@
"node": ">=4.0.0"
},
"dependencies": {
"promise-readable": "^3.1.1",
"promise-writable": "^3.1.0"
"promise-readable": "^3.1.3",
"promise-writable": "^3.1.1"
},
"devDependencies": {
"@types/node": "^9.4.0",
Expand Down
14 changes: 13 additions & 1 deletion test/promise-duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ Feature('Test promise-duplex module', () => {
return promise.should.eventually.deep.equal(Buffer.from('chunk1'))
})

And('stream can be destroyed', () => {
And('PromiseDuplex object can be destroyed', () => {
promiseDuplex.destroy()
})

And('PromiseDuplex object can be destroyed', () => {
promiseDuplex.destroy()
})
})
Expand Down Expand Up @@ -377,6 +381,14 @@ Feature('Test promise-duplex module', () => {
Then('promise is rejected', () => {
return promise.should.be.rejectedWith(Error, 'boom')
})

And('PromiseDuplex object can be destroyed', () => {
promiseDuplex.destroy()
})

And('PromiseDuplex object can be destroyed', () => {
promiseDuplex.destroy()
})
})

Scenario(`Wait for ${event} from stream with error emitted before method`, () => {
Expand Down

0 comments on commit 57bfe1f

Please sign in to comment.