-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support promises #19
Comments
@jpillora any thoughts on this? |
Hey Bronley, 9 months! Very patient :) I wonder if the GlobAll instance could extend Promise, and maintain existing functionality (emitting match and end events)? Otherwise I’m happy to change the return value to a Promise and bump the major version of this package👍 PR away! |
So, another 7 months have passed. I ended up switching glob libraries for a different reason for that project, but I'm back now because I need it for a new project :D I'm going to put together a PR for this with the GlobAll instance extending promise like you suggested. But before I do that, I wanted to verify with you are ok with requiring that If that concerns you, we could probably do something like this instead, which defers the promise usage to only once actually requested: Object.defineProperty(GlobAll.prototype, 'promise', {
get(){
if('undefined' === typeof Promise){
throw new Error('Promise is not supported in your environment');
} else{
//return the promise instance somehow
}
}
}); By doing this, we could allow glob-all to still work the same in all environments, and upgrade to using promises only when explicitly requested.
Thoughts? |
@jpillora what do you think of this approach? |
@jpillora thoughts on my proposal? |
glob@^9 supports promises and array of globs. Since this library is based on |
Yeah, I think that makes sense. |
It would be great if
node-glob-all
returned a promise for those of us who are moving away from the node callback model. Since nobody is expecting a return value from globAll, I would imagine this would be a pretty safe change to implement.I'm willing to do the work if you're interested in accepting the pull request.
I noticed that globAll returns the GlobAll instance, but this is undocumented. So with the assumption that nobody should actually be using the returned instance of GlobAll, this code would do the trick (untested):
If you must continue to return that GlobAll instance, then perhaps something like this would work, where it keeps the existing functionality, and only returns a promise when you do not provide a callback.
Usage
The text was updated successfully, but these errors were encountered: