Skip to content

Commit

Permalink
feat(connector): return promise on end
Browse files Browse the repository at this point in the history
  • Loading branch information
trs committed Jan 10, 2018
1 parent d22c911 commit 2255be9
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/connector/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@ class Connector {
}

end() {
if (this.dataSocket) this.dataSocket.end();
if (this.dataServer) this.dataServer.close();
this.dataSocket = null;
this.dataServer = null;
this.type = false;
const closeDataSocket = new Promise(resolve => {
if (this.dataSocket) this.dataSocket.end();
else resolve();
});
const closeDataServer = new Promise(resolve => {
if (this.dataServer) this.dataServer.close(() => resolve());
else resolve();
});

return Promise.all([closeDataSocket, closeDataServer])
.then(() => {
this.dataSocket = null;
this.dataServer = null;
this.type = false;
});
}
}
module.exports = Connector;

0 comments on commit 2255be9

Please sign in to comment.