function sleep(timeInMs: number) {
console.log("started " + timeInMs);
return new Promise<number>((res) => {
setTimeout(() => {
res(timeInMs);
}, timeInMs);
});
}
const queue = new AsyncQueue(3);
queue.exec(() => sleep(1000)).then(console.log);
queue.exec(() => sleep(10000)).then(console.log);
queue.exec(() => sleep(500)).then(console.log);
queue.exec(() => sleep(500)).then(console.log);
queue.exec(() => sleep(500)).then(console.log);
queue.exec(() => sleep(500)).then(console.log);
queue.exec(() => sleep(500)).then(console.log);
queue.exec(() => sleep(500)).then(console.log);
queue.exec(() => Promise.resolve("good days sir")).then(console.log);
queue.exec(() => sleep(6000)).then(console.log);
queue.exec(() => sleep(6000)).then(console.log);
-
Notifications
You must be signed in to change notification settings - Fork 0
random async queue implementation
License
phanshiyu/async-queue
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
random async queue implementation
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published