Skip to content

Instantly share code, notes, and snippets.

@MarkoSh
Last active September 6, 2025 09:48
Show Gist options
  • Save MarkoSh/c5899f8ac428512ebcbef8486a92805e to your computer and use it in GitHub Desktop.
Save MarkoSh/c5899f8ac428512ebcbef8486a92805e to your computer and use it in GitHub Desktop.
class RequestQueue {
queue: Promise<void> = Promise.resolve();
constructor() {
const $this = this;
}
async add(fn: any) {
const $this = this;
$this.queue = $this.queue.then(fn, fn);
return $this.queue;
}
}
const queue = new RequestQueue();
queue.add(async () => await fetch('https://google.com/1'));
queue.add(async () => await fetch('https://google.com/2'));
queue.add(async () => await fetch('https://google.com/3'));
const response: any = await queue.add(async () => await fetch('https://google.com/4'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment