All files / src duplicateRequestPrevent.ts

100% Statements 13/13
100% Branches 0/0
83.33% Functions 5/6
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 232x   2x   2x 265x 265x 210x       2x 464x     2x 309x     2x 48x    
export { generateRequestHash  } from "./utils"
 
const pendingRequest: Record<string, any> = {}
 
export function addPendingRequest(hash: string, request: Promise<any>, timeout: number) {
  pendingRequest[hash] = request
  setTimeout(() => {
    clearPendingRequest(hash)
  }, timeout)
}
 
export function clearPendingRequest(hash: string) {
  Reflect.deleteProperty(pendingRequest, hash)
}
 
export function checkIfHasPendingRequest(hashKey: string): boolean {
  return Reflect.has(pendingRequest, hashKey)
}
 
export function getCachedRequest(hashKey: string) {
  return pendingRequest[hashKey]
}