Skip to content
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

Attempting to resolve promises with more than one value #23

Open
ariesshrimp opened this issue Oct 13, 2016 · 1 comment
Open

Attempting to resolve promises with more than one value #23

ariesshrimp opened this issue Oct 13, 2016 · 1 comment

Comments

@ariesshrimp
Copy link
Collaborator

// lib/core/file.js
function isDirectoryEmpty(path) {
    return new Promise((resolve, reject) => {
                ...
                resolve(noFilesPresent, path); // I think this is impossible?
                ...
    });
}

I don't think that native promises can be resolved with more than one value. I would expect path to be lost here without fail. I caught this while trying to experimenting with adding Flow type annotations for some inline documentation.

@chalkers, do you know if that's right? Haven't chased the thread here yet to see what the expected behavior is.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then

@soulchild
Copy link

soulchild commented Jul 7, 2017

You're right: A promise can only yield one result. I believe a method named isDirectoryEmpty should return exactly that: A boolean value indicating whether the directory is empty or not. If you really want to return the path as well, you may return an object instead:

resolve({ 
  isEmpty: noFilesPresent, 
  path 
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants