Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why we need await Promise.resolve() in enqueue #82

Closed
zingxy opened this issue Jun 13, 2024 · 1 comment
Closed

Why we need await Promise.resolve() in enqueue #82

zingxy opened this issue Jun 13, 2024 · 1 comment

Comments

@zingxy
Copy link

zingxy commented Jun 13, 2024

(async () => {
	// This function needs to wait until the next microtask before comparing
	// `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
	// when the run function is dequeued and called. The comparison in the if-statement
	// needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
	await Promise.resolve(); 

	if (activeCount < concurrency && queue.size > 0) {
		queue.dequeue()();
	}
})();

Can you give me some concrete example? Thank you!

@sindresorhus
Copy link
Owner

#28

@zingxy zingxy closed this as completed Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants