why `await`?
See original GitHub issueCool project, but I am confused that why you use await
in your example:
const { Cluster } = require('puppeteer-cluster');
(async () => {
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 2,
});
// Is `await` necessary?
await cluster.task(async ({ page, data: url }) => {
await page.goto(url);
const screen = await page.screenshot();
// Store screenshot, do something else
});
await cluster.queue('http://www.google.com/');
await cluster.queue('http://www.wikipedia.org/');
// many more pages
await cluster.idle();
await cluster.close();
})();
when you define a task
or try to add some queues, why await
? I try to remove them and is ok to do that.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
When and How to use Async/Await? | Thirdock Techkno
They keyword async is used to make a function asynchronous. The await keyword will ask the execution to wait until the defined task...
Read more >All you need to know about Async Await In JavaScript - Medium
Await and Async keyword combined together ensures that the main thread will not start executing further until the asynchronous part of the application...
Read more >await operator - asynchronously wait for a task to complete
The await operator suspends evaluation of the enclosing async method until the asynchronous operation represented by its operand completes.
Read more >How and when to use 'async' and 'await' - Stack Overflow
Short answer which might help. async/await is single thread event based model. Which allows you to run code out-of-order until the line of...
Read more >How to Use Async/Await in JavaScript with Example JS Code
Async/Await makes it easier to write promises. The keyword 'async' before a function makes the function return a promise, always. And the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I removed the
await
s from allcluster.queue
examples and added this hint to the docs:“Be aware that this function only returns a Promise for backward compatibility reasons. This function does not run asynchronously and will immediately return.”
I guess that should clear any confusion in the future.
Option 2 seems nice.