28 lines
589 B
TypeScript
28 lines
589 B
TypeScript
export interface RelayResponse
|
|
{
|
|
reqId: string;
|
|
status: number;
|
|
headers: Record<string, string>;
|
|
body: string; // base64-encoded
|
|
}
|
|
|
|
const callbacks = new Map<string, ( r: RelayResponse ) => void>();
|
|
|
|
export function addPending( reqId: string, cb: ( r: RelayResponse ) => void ): void
|
|
{
|
|
callbacks.set( reqId, cb );
|
|
}
|
|
|
|
export function resolvePending( resp: RelayResponse ): void
|
|
{
|
|
const cb = callbacks.get( resp.reqId );
|
|
if ( !cb ) return;
|
|
callbacks.delete( resp.reqId );
|
|
cb( resp );
|
|
}
|
|
|
|
export function removePending( reqId: string ): void
|
|
{
|
|
callbacks.delete( reqId );
|
|
}
|