From ea7610e1a03dd555da974fc03bc3eeae4d31b80c Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sun, 17 Mar 2019 13:51:36 -0700 Subject: [PATCH] bind close method --- .gitignore | 1 + .npmignore | 1 + package.json | 1 - src/consumer.js | 7 +++++-- src/socket-class.js | 3 ++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index bd8d34e..28703d5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.log /temp/ *.lock +/archive/ diff --git a/.npmignore b/.npmignore index 66591e2..93bc8e2 100644 --- a/.npmignore +++ b/.npmignore @@ -6,3 +6,4 @@ examples/ yarn.lock travis.yml .eslintrc.js +archive/ diff --git a/package.json b/package.json index d391e53..d1969d5 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "esm": "^3.0.84", "istanbul": "^0.4.5", "mocha": "^5.2.0", - "mz": "^2.7.0", "nodemon": "^1.18.6" }, "dependencies": { diff --git a/src/consumer.js b/src/consumer.js index 3f26826..1fff8d3 100644 --- a/src/consumer.js +++ b/src/consumer.js @@ -1,5 +1,6 @@ import { Socket } from 'net' import path from 'path' +import { promisify } from 'util' import btc from 'better-try-catch' import JsonStream from './json-stream' @@ -46,11 +47,12 @@ class SocketConsumer extends Socket { this.opts = opts this.keepAlive = 'keepAlive' in opts ? opts.keepAlive : true this._ready = false - this.timeout = opts.timeout || 30 + this.timeout = opts.timeout || 30 // 5 minutes and then rejects this.wait = opts.wait || 1 this.stream = new JsonStream() // bind to class for other class functions this.connect = this.connect.bind(this) + this.close = promisify(this.end).bind(this) this.__ready = this.__ready.bind(this) // this._write = this._write.bind(this) } @@ -70,6 +72,7 @@ class SocketConsumer extends Socket { } let reconnect = {} + // this is only for initial connection const timeout = setTimeout(() => { clearTimeout(reconnect) log.fatal({ opts: this.opts }, `unable to connect in ${this.timeout}s`) @@ -193,7 +196,7 @@ class SocketConsumer extends Socket { let res = await this._packetProcess(packet) if (!res) { // if process was not promise returning like just logged to console - // log.warn('consumer function was not promise returning') + log.warn('consumer packet processing function was not promise returning') } }) // listen on socket stream diff --git a/src/socket-class.js b/src/socket-class.js index 55cfb6d..8d7985c 100644 --- a/src/socket-class.js +++ b/src/socket-class.js @@ -54,7 +54,7 @@ export default function socketClass(Server) { } else { if (typeof opts.path === 'boolean') opts.path = path.join(DEFAULT_PIPE_DIR, DEFAULT_SOCKET_NAME) - if (path.dirname(opts.path) === '.') + if (path.dirname(opts.path) === '.') // relative path sent opts.path = path.join(DEFAULT_PIPE_DIR, opts.path) } this.clientTracking = opts.clientTracking || true @@ -63,6 +63,7 @@ export default function socketClass(Server) { //self bindings this._listen = this._listen.bind(this) this.create = this.create.bind(this) + this.close = promisify(this.close).bind(this) log = logger({ file: 'src/socket.js', class: 'Socket',