Skip to content

Commit

Permalink
Added backoff delay to enterServiceRoom function
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkonst committed Aug 28, 2023
1 parent 6223979 commit b36a7e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulms/api-clients",
"version": "5.27.0",
"version": "5.28.0",
"description": "JavaScript API clients for ULMS platform",
"keywords": [],
"homepage": "https://github.com/foxford/ulms-api-clients-js#readme",
Expand Down
14 changes: 12 additions & 2 deletions src/common.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Backoff from './backoff'
import { TimeoutError } from './error'

// eslint-disable-next-line default-param-last
Expand Down Expand Up @@ -61,10 +62,11 @@ export async function enterServiceRoom(
roomId,
id,
label,
delay,
minDelay,
trackEvent,
serviceName
) {
const backoff = new Backoff(minDelay)
const EVENT_NAME = 'room.enter'
const isTransportConnected = () => client.mqtt.connected
let enterRoomSuccess = false
Expand Down Expand Up @@ -97,16 +99,24 @@ export async function enterServiceRoom(
if (enterRoomSuccess) break

// eslint-disable-next-line no-await-in-loop
await sleep(delay)
await sleep(backoff.value)

backoff.next()

if (enterRoomSuccess) break

trackEvent('Debug', `${serviceName}.Subscription.Retry`)
}
} catch (error) {
client.off(EVENT_NAME, handler)

backoff.reset()

throw error
}

backoff.reset()

return response
}

Expand Down

0 comments on commit b36a7e8

Please sign in to comment.