bind close method

This commit is contained in:
David Kebler 2019-03-17 13:51:36 -07:00
parent b587d5f2f2
commit ea7610e1a0
5 changed files with 9 additions and 4 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@
*.log
/temp/
*.lock
/archive/

View file

@ -6,3 +6,4 @@ examples/
yarn.lock
travis.yml
.eslintrc.js
archive/

View file

@ -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": {

View file

@ -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

View file

@ -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',