Last active
September 6, 2025 09:48
-
-
Save MarkoSh/c5899f8ac428512ebcbef8486a92805e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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