skolplattformen-backup/libs/api-skolplattformen/lib/queueFetcherWrapper.ts

20 lines
617 B
TypeScript
Raw Normal View History

2022-02-11 17:31:24 +00:00
import QueueFetcher from './queue/queueFetcher'
import {Fetcher, RequestInit, Response } from '@skolplattformen/api'
export default function queueFetcherWrapper(fetch: Fetcher,
changeChildFunc: ((childId: string) => Promise<Response>)) : Fetcher {
const queue = new QueueFetcher(changeChildFunc)
queue.verboseDebug = true
return async (name: string, url: string, init: RequestInit = { headers: {} }, childId? : string)
: Promise<Response> => {
if (childId === undefined) {
return fetch(name, url, init)
}
const p = queue.fetch(() => fetch(name, url, init), childId)
return p
}
}