1import { Fetcher } from '../../pkg';
2
3function sleep(ms: number) {
4    return new Promise(resolve => setTimeout(resolve, ms));
5}
6
7export class CdnFetcher implements Fetcher {
8    private cache: { [lang: string]: string } = {};
9    async fetchLocale(lang: string) {
10        if (typeof this.cache[lang] === 'string') {
11            return this.cache[lang];
12        }
13        // this works
14        // console.log(lang, "sleeping");
15        // await sleep(400);
16        // console.log(lang, "waking");
17        let res = await fetch(`https://cdn.rawgit.com/citation-style-language/locales/master/locales-${lang}.xml`);
18        if (res.ok) {
19            let text = await res.text();
20            this.cache[lang] = text;
21            return text;
22        }
23    }
24}
25