-
Notifications
You must be signed in to change notification settings - Fork 64
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
added an example for passing a result to the success handler #64
Conversation
Thanks for the patch - the example in the readme is (or at least should be) an exact copy of the code here: Ideally, I'd like to keep this executable, and mirror what's in the example program, can you update this pr accordingly? |
Sure thing, stand by. |
included an example of passing the result of a resolved promise to the 'success' event listener. Also shows how to pass an error from a rejected promise. Fixed some style errors.
Ok, updated the example index.js file |
thanks, now that i can run the example this is a little easier for me to understand. having implemented this: and answered related questions here: I wonder if we're documenting this in a way that's more confusing than it should be... if you're willing, it would be awesome to know if you had considered using |
basically, I wrote the example before the |
Honestly, I didn’t look at the tests. But I understand more about how the opts.results array was intended to be used now after I have. For me the results had to be handled in different ways using a switch based on the type of data received. Using the opts.results array I could iterate and pass each result to the switch. But the success handler seems to eliminate that step. I know how much time writing docs can take, and just thought I’d make a suggestion based on something I had trouble with. Otherwise this module has worked very well for me and saved a lot of time by being simple to implement and robust. |
Heard. It would be nice to have both ways documented.. I can't work on it today but soon I'll merge this and add a commit to change the example over to use |
asyncJob() | ||
.then((result) => cb(null, result)) | ||
.catch((error) => cb(error)) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may be able to do q.push(asyncJob)
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I agree, you could just return a promise. If we want to demonstrate how to pass a result
into a callback()
then maybe a different approach would work for you.
}) | |
const result = 'this is a long stream of data' | |
cb(null, result) | |
}) |
Now that I understand how you intended |
oh, feel free. for the success handler, is it as simple as just adding the result to the existing console.log? https://github.com/jessetane/queue/blob/master/example/index.js#L75 |
Yes, adding the result argument to the log would work. So long as you don't mind printing |
incorporated examples of how to use the results array
Alright, take a look at the latest commit and let me know what you think. |
might make a couple small tweaks but generally lgtm. sorry for the delay, thanks for the help! |
Here is a suggestion for some additional documentation. I had trouble figuring this out through trial and error.