-
Notifications
You must be signed in to change notification settings - Fork 55
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
Can we promisfy js-crawler #27
Comments
Hi, Actually the result of invoking Promise resolves to a single value and crawler produces a series of values the length of which we do not know upfront, so we cannot just return a Promise from the I agree that it would be nice to think about some alternatives to callback-based API. |
I don't think promisifying the crawler API itself really makes sense, based on the fact that it is a many-result not a single-result system... it is better suited to the event listener system in place currently. (Re: antivanov's comment.) What I did to adapt it to my promise-based system, for those interested:
Basically, the "results" object would be used to contain anything you want to pass back after the promise resolves, and the promise resolves after the crawling completes. You could add a reject() to handle errors as well, if you want the promise to fail in certain cases. To use this, it is as simple as any other promise/thenable function:
|
Can you help me show, if we can promisfy the below js-crawler.
is there better way to return the response from each crawler state.
The text was updated successfully, but these errors were encountered: