-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Allow resolving with a custom value #25
Conversation
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
@Richienb The method should be attached to the method, as discussed in #25 (comment) |
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
Not a fan of this, my suggestion used the standard method used by the Promise constructor, without having to reference pWaitFor itself |
I think an issue with using the Promise constructor is the suboptimal support for TypeScript since the types can't be auto-inferred and need to be explicitly specified with the generic argument (which isn't always practical). I believe this is a TypeScript limitation since I don't think there's a way to have the generic parameter auto-inferred in |
An alternative would be to have an option deciding how to handle the returned value:
If you want to really return undefined then you could supply a symbol: The current default where the returned value is ignored is kind of annoying. |
Boolean, not truthy/falsy. |
Would be a strange API. |
I personally think using a symbol-returning method for this is an elegant solution. |
This package has existed for years without the direct ability to return a value and you are the only ones that have requested it, so I don't think it's a common need either. |
We could consider some nice handling for the case of wanting the value when it's not undefined, instead of checking a boolean. Some ideas: import pWaitFor from 'p-wait-for';
const path = await pWaitFor.defined(async () => await getPath());
console.log(path); import pWaitFor from 'p-wait-for';
const path = await pWaitFor(async () => {
let path = await getPath();
return pWaitFor.resolveIfDefined(path);
});
console.log(path); |
Fixes #12
Fixes #22
Fixes #23