From 9c28dde04d5f9e797e5d31a48912f2044b2f07ac Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Tue, 18 Oct 2022 16:57:40 +0530 Subject: [PATCH] chore: call processInBuffer for all msg handling --- src/Socket/messages-recv.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Socket/messages-recv.ts b/src/Socket/messages-recv.ts index 7acc8c7..b725ce1 100644 --- a/src/Socket/messages-recv.ts +++ b/src/Socket/messages-recv.ts @@ -617,17 +617,16 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { } } - const flushBufferIfLastOfflineNode = ( + /// processes a node with the given function + /// and adds the task to the existing buffer if we're buffering events + const processNodeWithBuffer = ( node: BinaryNode, identifier: string, exec: (node: BinaryNode) => Promise ) => { const task = exec(node) .catch(err => onUnexpectedError(err, identifier)) - const offline = node.attrs.offline - if(offline) { - ev.processInBuffer(task) - } + ev.processInBuffer(task) } // called when all offline notifs are handled @@ -643,19 +642,19 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => { // recv a message ws.on('CB:message', (node: BinaryNode) => { - flushBufferIfLastOfflineNode(node, 'processing message', handleMessage) + processNodeWithBuffer(node, 'processing message', handleMessage) }) ws.on('CB:call', async(node: BinaryNode) => { - flushBufferIfLastOfflineNode(node, 'handling call', handleCall) + processNodeWithBuffer(node, 'handling call', handleCall) }) ws.on('CB:receipt', node => { - flushBufferIfLastOfflineNode(node, 'handling receipt', handleReceipt) + processNodeWithBuffer(node, 'handling receipt', handleReceipt) }) ws.on('CB:notification', async(node: BinaryNode) => { - flushBufferIfLastOfflineNode(node, 'handling notification', handleNotification) + processNodeWithBuffer(node, 'handling notification', handleNotification) }) ws.on('CB:ack,class:message', (node: BinaryNode) => {