-
-
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
Resolve with return value #12
Comments
It's expected to return a boolean though, not a truthy value. I'm generally not a fan of truthy checks, as it's impossible to type in TS and can cause bugs. If you need the value, I think we could design something around that. Maybe: const pWaitFor = require('p-wait-for');
const pathExists = require('path-exists');
(async () => {
const path = await pWaitFor.withValue(() => {
let path = getPath();
return {
isTrue: pathExists(path),
returnValue: path
};
});
console.log(path);
})(); I'm open to suggestions if you can think of something more elegant. |
const pWaitFor = require('p-wait-for');
const pathExists = require('path-exists');
(async () => {
const path = await pWaitFor((resolve) => {
let path = getPath();
if (pathExists(path)) {
resolve(path)
}
});
console.log(path);
})(); |
I would also suggest tightening the This makes it a little more annoying since you must |
I agree, the types should be made stricter, also the JS validation. |
This should resolve with the return value of the function that returns the truthy value. This is useful for promise-returning functions that return either a value or undefined.
The text was updated successfully, but these errors were encountered: