const oldGet = Axios.get;
const promiseQueue: Promise<any>[] = [];
const serialGet = async (url: string) => {
const curIdx = promiseQueue.length - 1;
if (curIdx != -1) {
await promiseQueue[curIdx];
}
const getData = oldGet(url);
promiseQueue.push(getData);
return await getData;
};
This is my solution for serializing http get method in node.
But it seems do not work, no matter promiseQueue[curIdx]
is a resolved Promise
or not, await
will give up its execution.
It's there any solution meet my need?