question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cool 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
thomasdondorfcommented, Mar 6, 2019

I removed the awaits from all cluster.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.

1reaction
SidKwokcommented, Mar 6, 2019

Option 2 seems nice.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found