idleberg idleberg - 7 months ago 39
Node.js Question

Return value from async function from its parent

I'm working on a build provider for the Atom text editor, which is a component based on the

package. This package allows you to run some tests to check whether a provider is eligible to run or not, returning

I'm using
to check whether a certain file-type is present in the project folder to determine whether to activate the build provider. For example, a project folder should include a LESS file in order to activate a build provider for


isEligible() {
const paths = glob.sync("**/*.less");

if (paths.length > 0) {
// one or more LESS files found
return true;

// no LESS files found
return false;

I'm wondering if the same is possible using
asynchronously, specifically how I can return the state from
. The following does not work:

isEligible() {
return glob("**/*.less", function (err, files) {
if (err) {
return false;

return true;


The following does not work

Yes. It absolutely cannot work.

If the caller of isEligible (i.e. the build package) does not support asynchrony, then you have to make your function synchronous, there is no way around it. You might file a feature request for providing a callback to isEligible or accepting a promise as the return value, though.