Fix another possible race condition
This commit is contained in:
@@ -12,7 +12,8 @@ let dispatch = null
|
|||||||
let timeout = null
|
let timeout = null
|
||||||
|
|
||||||
const getEventStream = async () => {
|
const getEventStream = async () => {
|
||||||
if (es === null) {
|
if (!es) {
|
||||||
|
// Call `keepalive` to refresh the jwt token
|
||||||
await httpClient(`${REST_URL}/keepalive/eventSource`)
|
await httpClient(`${REST_URL}/keepalive/eventSource`)
|
||||||
es = new EventSource(
|
es = new EventSource(
|
||||||
baseUrl(`${REST_URL}/events?jwt=${localStorage.getItem('token')}`)
|
baseUrl(`${REST_URL}/events?jwt=${localStorage.getItem('token')}`)
|
||||||
@@ -24,15 +25,15 @@ const getEventStream = async () => {
|
|||||||
// Reestablish the event stream after 20 secs of inactivity
|
// Reestablish the event stream after 20 secs of inactivity
|
||||||
const setTimeout = (value) => {
|
const setTimeout = (value) => {
|
||||||
currentIntervalCheck = value
|
currentIntervalCheck = value
|
||||||
if (timeout != null) {
|
if (timeout) {
|
||||||
window.clearTimeout(timeout)
|
window.clearTimeout(timeout)
|
||||||
}
|
}
|
||||||
timeout = window.setTimeout(() => {
|
timeout = window.setTimeout(async () => {
|
||||||
if (es != null) {
|
if (es) {
|
||||||
es.close()
|
es.close()
|
||||||
}
|
}
|
||||||
es = null
|
es = null
|
||||||
startEventStream(dispatch)
|
await startEventStream(dispatch)
|
||||||
}, currentIntervalCheck)
|
}, currentIntervalCheck)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ const stopEventStream = () => {
|
|||||||
es.close()
|
es.close()
|
||||||
}
|
}
|
||||||
es = null
|
es = null
|
||||||
if (timeout != null) {
|
if (timeout) {
|
||||||
window.clearTimeout(timeout)
|
window.clearTimeout(timeout)
|
||||||
}
|
}
|
||||||
timeout = null
|
timeout = null
|
||||||
|
|||||||
Reference in New Issue
Block a user