Skip to content

Commit

Permalink
send ws message with delay
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytroshch committed Sep 11, 2023
1 parent fa607eb commit 50022c0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/redux/sagas/ws/worker_message_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ONLINE_ONLY_MESSAGES = [
'settings.update',
]
let queue = []
let isQueueExecuted = false
let isQueueExecuting = false

export default function* messageQueueWorker(action = {}) {
const sockets = yield select(getSockets)
Expand All @@ -33,16 +33,15 @@ export default function* messageQueueWorker(action = {}) {
}
if (action.type !== WSTypes.FLUSH_QUEUE) {
queue = [...queue, action]
if (isQueueExecuted) {
if (isQueueExecuting) {
return
}
}

if (offline || queue.length === 0) {
return
}
isQueueExecuted = true
yield delay(500)
isQueueExecuting = true
debug('flushing %d messages')

for (let i = 0; i < queue.length; i += 1) {
Expand All @@ -51,10 +50,10 @@ export default function* messageQueueWorker(action = {}) {
if (queuedAction.type === WSTypes.BUFF_SEND) {
queuedAction.type = WSTypes.SEND
}

yield delay(500)
yield put(queuedAction)
}

queue = []
isQueueExecuted = false
isQueueExecuting = false
}

0 comments on commit 50022c0

Please sign in to comment.