Import AITURK IDE 1.0.0-beta.1 from Hermes 63279301; preserve MIT license
This commit is contained in:
commit
03634b1ca3
11340 files changed
+3442369
No files matched your search
@@ -0,0 +1,34 @@
|
||||
type GatewayReconnectHandler = () => Promise<void> | void
|
||||
|
||||
let activeHandler: GatewayReconnectHandler | null = null
|
||||
let inFlight: Promise<void> | null = null
|
||||
|
||||
export function registerGatewayReconnect(handler: GatewayReconnectHandler): () => void {
|
||||
activeHandler = handler
|
||||
|
||||
return () => {
|
||||
if (activeHandler === handler) {
|
||||
activeHandler = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function reconnectGateway(): Promise<void> {
|
||||
if (inFlight) {
|
||||
return inFlight
|
||||
}
|
||||
|
||||
const handler = activeHandler
|
||||
|
||||
if (!handler) {
|
||||
return Promise.reject(new Error('Gateway reconnect is unavailable'))
|
||||
}
|
||||
|
||||
inFlight = Promise.resolve()
|
||||
.then(handler)
|
||||
.finally(() => {
|
||||
inFlight = null
|
||||
})
|
||||
|
||||
return inFlight
|
||||
}
|
||||
Reference in new issue
Block a user