@mrmory/bggclient
Version:
Javascript client to interact with BoardGameGeek public XML API based on boardgamegeekjsclient
26 lines (21 loc) • 722 B
text/typescript
import { IFetcher } from "../interface";
import fetch from 'isomorphic-unfetch';
export class TextFetcher implements IFetcher<string, string> {
async doFetch(query: string): Promise<string> {
let response = await this.internalFetch(query);
while (response.status === 202) {
await this.delay(6000);
response = await this.internalFetch(query);
}
return response.text();
}
async internalFetch(query: string): Promise<any> {
const response = await fetch(query);
return response;
}
async delay(waitFor: number): Promise<any> {
return new Promise((resolve) => {
setTimeout(resolve, waitFor);
});
}
}