Skip to content

Commit

Permalink
Fixed the method close for TCP connection provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
fenying committed May 28, 2018
1 parent 7de35e6 commit 5b4e3cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -3,3 +3,4 @@
## v0.1.1

- Added option `connectTimeout` for TCP connection provider.
- Fixed the method `close` for TCP connection provider.
6 changes: 6 additions & 0 deletions src/samples/redis.ts
Expand Up @@ -32,6 +32,10 @@ connector.on("connected", function() {
c.on("data", function(data) {

console.log(data.toString());

}).on("end", function() {

console.log("Ended.");
});

c.write("AUTH redis-passwd\r\n");
Expand All @@ -46,6 +50,8 @@ connector.on("connected", function() {

c.write("MGET d b\r\n");

setTimeout(() => connector.close(), 5000);

}).on("error", function(e) {

console.error(e);
Expand Down
5 changes: 2 additions & 3 deletions src/tcp.ts
Expand Up @@ -83,10 +83,9 @@ implements ConnectionProvider<$Net.Socket, NodeJS.ErrnoException> {

public close(): void {

if (this._conn && !this._conn.destroyed) {
if (this._conn && this._conn.writable) {

this._conn.destroy();
delete this._conn;
this._conn.end();
}
}

Expand Down

0 comments on commit 5b4e3cb

Please sign in to comment.