0.3.2 catch no consumer on send
This commit is contained in:
parent
9528e71abb
commit
b856710a3b
2 changed files with 16 additions and 5 deletions
10
package.json
10
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@uci/socket",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.2",
|
||||
"description": "JSON packet intra(named)/inter(TCP) host communication over socket",
|
||||
"main": "src",
|
||||
"scripts": {
|
||||
|
@ -43,16 +43,16 @@
|
|||
"chai": "^4.2.0",
|
||||
"chai-as-promised": "^7.1.1",
|
||||
"esm": "^3.2.25",
|
||||
"mocha": "^7.1.1",
|
||||
"nodemon": "^2.0.2"
|
||||
"mocha": "^8.0.1",
|
||||
"nodemon": "^2.0.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@uci-utils/logger": "^0.0.16",
|
||||
"@uci-utils/logger": "^0.0.18",
|
||||
"better-try-catch": "^0.6.2",
|
||||
"clone": "^2.1.2",
|
||||
"death": "^1.1.0",
|
||||
"delay": "^4.3.0",
|
||||
"make-dir": "^3.0.2",
|
||||
"make-dir": "^3.1.0",
|
||||
"p-reflect": "^2.1.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -477,12 +477,23 @@ export default function socketClass(Server) {
|
|||
async _send(consumer, packet) {
|
||||
log.trace({msg:`sending to consumer:${consumer.sid}:${consumer.data.name}`, consumer:consumer.data, packet:packet})
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (!consumer) {
|
||||
console.log('no consumer rejecting packet send')
|
||||
reject('no consumer specified can not send packet')
|
||||
return
|
||||
}
|
||||
if (!consumer.writable) {
|
||||
console.log('no consumer writeable stream rejecting packet send')
|
||||
reject('socket stream closed can not send packet')
|
||||
return
|
||||
}
|
||||
let [err,ser] = await btc(consumer.stream.serialize)(packet)
|
||||
if (err) reject('unable to serialze the packet')
|
||||
if (!ser) {
|
||||
console.log('empty-seriallized packet', consumer.name, consumer.socketName)
|
||||
reject('empty packet rejecting send, nothing to send')
|
||||
return
|
||||
}
|
||||
const cb = () => resolve('packet written to socket stream')
|
||||
if (!consumer.write(ser)) {
|
||||
consumer.once('drain', cb)
|
||||
|
|
Loading…
Reference in a new issue