GithubHelp home page GithubHelp logo

Comments (10)

SidKwok avatar SidKwok commented on May 21, 2024 1

Option 2 seems nice.

from puppeteer-cluster.

thomasdondorf avatar thomasdondorf commented on May 21, 2024 1

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.

from puppeteer-cluster.

thomasdondorf avatar thomasdondorf commented on May 21, 2024

The await there is currently not really needed (it's also not needed for cluster.queue by the way). It's there for two reasons:

  1. Consistency: All functions on cluster.* return Promises. That way you don't need to worry whether to use await or not when dealing with the cluster functions. Just use it everywhere and you are fine.
  2. Forward compatibility: Right now the functions task and queue have only synchronous calls inside. That means right now we don't need Promises. I can imagine that in the future this might change. There are several use cases for this. Imaging we want to log data asynchronously when queue or task is called. Or maybe we want to store the queued data into a database instead of an array.

Hope that makes sense.

from puppeteer-cluster.

SidKwok avatar SidKwok commented on May 21, 2024

Right now the functions task and queue have only synchronous calls inside.

You mean cluster.queue('http://www.wikipedia.org/') will be called after cluster.queue('http://www.google.com/') finish?

from puppeteer-cluster.

thomasdondorf avatar thomasdondorf commented on May 21, 2024

No, I meant there are no await (asynchronous) calls inside of the task and queue functions. The functions are very simple and don't need to be async right now.

from puppeteer-cluster.

SidKwok avatar SidKwok commented on May 21, 2024

I got it. The doc indicate that all functions on cluster.* return Promises. The example may cause confusion that cluster.queue('http://www.wikipedia.org/') will be called after cluster.queue('http://www.google.com/') finish, take axios as example:

await axios.get('http://api.org/get-name');
// will be called after the above function is finished
await axios.get('http://api.org/get-age');

// both will be called asynchronously
axios.get('http://api.org/get-name');
axios.get('http://api.org/get-age');

Hope it only causes confusion for me lol.

from puppeteer-cluster.

thomasdondorf avatar thomasdondorf commented on May 21, 2024

Thank you. I had not thought about it that way. Maybe the await should be removed then?

I have to think about this. Feedback is welcome :)

from puppeteer-cluster.

thomasdondorf avatar thomasdondorf commented on May 21, 2024

await really seems to confuse people: https://stackoverflow.com/questions/46597304/how-to-enable-parallel-tests-with-puppeteer/51408815#comment92960172_51408815

Currently I'm in favor of removing await from the documentation, but keeping the returning of a Promise to not break compatibility with previous versions.

from puppeteer-cluster.

SidKwok avatar SidKwok commented on May 21, 2024

I think people would use queue to define a task and add it to end of the queue. Is it really necessary to return a Promise in this case?

from puppeteer-cluster.

thomasdondorf avatar thomasdondorf commented on May 21, 2024

I implemented the execute function which hopefully makes things clearer. Right now I think there are three options on how to proceed:

  1. Remove Promise from queue function and return void instead of Promise<void>
  2. Still return a Promise, but remove all await cluster.queue(..) from documentation
  3. Continue as is.

I prefer option 2 as this keeps backward compatibility and will hopefully make it more clear through documentation.

from puppeteer-cluster.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.