bind close method
parent
b587d5f2f2
commit
ea7610e1a0
|
@ -4,3 +4,4 @@
|
||||||
*.log
|
*.log
|
||||||
/temp/
|
/temp/
|
||||||
*.lock
|
*.lock
|
||||||
|
/archive/
|
||||||
|
|
|
@ -6,3 +6,4 @@ examples/
|
||||||
yarn.lock
|
yarn.lock
|
||||||
travis.yml
|
travis.yml
|
||||||
.eslintrc.js
|
.eslintrc.js
|
||||||
|
archive/
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
"esm": "^3.0.84",
|
"esm": "^3.0.84",
|
||||||
"istanbul": "^0.4.5",
|
"istanbul": "^0.4.5",
|
||||||
"mocha": "^5.2.0",
|
"mocha": "^5.2.0",
|
||||||
"mz": "^2.7.0",
|
|
||||||
"nodemon": "^1.18.6"
|
"nodemon": "^1.18.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Socket } from 'net'
|
import { Socket } from 'net'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import { promisify } from 'util'
|
||||||
import btc from 'better-try-catch'
|
import btc from 'better-try-catch'
|
||||||
import JsonStream from './json-stream'
|
import JsonStream from './json-stream'
|
||||||
|
|
||||||
|
@ -46,11 +47,12 @@ class SocketConsumer extends Socket {
|
||||||
this.opts = opts
|
this.opts = opts
|
||||||
this.keepAlive = 'keepAlive' in opts ? opts.keepAlive : true
|
this.keepAlive = 'keepAlive' in opts ? opts.keepAlive : true
|
||||||
this._ready = false
|
this._ready = false
|
||||||
this.timeout = opts.timeout || 30
|
this.timeout = opts.timeout || 30 // 5 minutes and then rejects
|
||||||
this.wait = opts.wait || 1
|
this.wait = opts.wait || 1
|
||||||
this.stream = new JsonStream()
|
this.stream = new JsonStream()
|
||||||
// bind to class for other class functions
|
// bind to class for other class functions
|
||||||
this.connect = this.connect.bind(this)
|
this.connect = this.connect.bind(this)
|
||||||
|
this.close = promisify(this.end).bind(this)
|
||||||
this.__ready = this.__ready.bind(this)
|
this.__ready = this.__ready.bind(this)
|
||||||
// this._write = this._write.bind(this)
|
// this._write = this._write.bind(this)
|
||||||
}
|
}
|
||||||
|
@ -70,6 +72,7 @@ class SocketConsumer extends Socket {
|
||||||
}
|
}
|
||||||
|
|
||||||
let reconnect = {}
|
let reconnect = {}
|
||||||
|
// this is only for initial connection
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
clearTimeout(reconnect)
|
clearTimeout(reconnect)
|
||||||
log.fatal({ opts: this.opts }, `unable to connect in ${this.timeout}s`)
|
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)
|
let res = await this._packetProcess(packet)
|
||||||
if (!res) {
|
if (!res) {
|
||||||
// if process was not promise returning like just logged to console
|
// 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
|
// listen on socket stream
|
||||||
|
|
|
@ -54,7 +54,7 @@ export default function socketClass(Server) {
|
||||||
} else {
|
} else {
|
||||||
if (typeof opts.path === 'boolean')
|
if (typeof opts.path === 'boolean')
|
||||||
opts.path = path.join(DEFAULT_PIPE_DIR, DEFAULT_SOCKET_NAME)
|
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)
|
opts.path = path.join(DEFAULT_PIPE_DIR, opts.path)
|
||||||
}
|
}
|
||||||
this.clientTracking = opts.clientTracking || true
|
this.clientTracking = opts.clientTracking || true
|
||||||
|
@ -63,6 +63,7 @@ export default function socketClass(Server) {
|
||||||
//self bindings
|
//self bindings
|
||||||
this._listen = this._listen.bind(this)
|
this._listen = this._listen.bind(this)
|
||||||
this.create = this.create.bind(this)
|
this.create = this.create.bind(this)
|
||||||
|
this.close = promisify(this.close).bind(this)
|
||||||
log = logger({
|
log = logger({
|
||||||
file: 'src/socket.js',
|
file: 'src/socket.js',
|
||||||
class: 'Socket',
|
class: 'Socket',
|
||||||
|
|
Loading…
Reference in New Issue