mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +00:00
fix(core): throwing in tcpSend onData callback would crash (#705)
* fix(core): throwing in tcpSend onData callback would crash * docs: update changelog for these changes
This commit is contained in:
parent
49093f0b0f
commit
da78c84c03
2 changed files with 8 additions and 2 deletions
|
|
@ -222,11 +222,16 @@ export default class Core extends EventEmitter {
|
|||
async tcpSend (socket, buffer, ondata) {
|
||||
let timeout
|
||||
try {
|
||||
const promise = new Promise((resolve, _reject) => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
let received = Buffer.from([])
|
||||
const onData = (data) => {
|
||||
received = Buffer.concat([received, data])
|
||||
const result = ondata(received)
|
||||
let result
|
||||
try {
|
||||
result = ondata(received)
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
if (result !== undefined) {
|
||||
socket.removeListener('data', onData)
|
||||
resolve(result)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue