Last active
December 20, 2015 15:59
-
-
Save larzconwell/6158099 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var async = require('async'); | |
function some (items, iterator) { | |
var ret = -1, | |
v; | |
for (var i in items) { | |
v = iterator(items[i]); | |
if (v) { | |
ret = i; | |
break; | |
} | |
} | |
return ret; | |
} | |
async.parallel([ | |
function (done) { | |
done(null, null); | |
}, | |
function (done) { | |
done(null, 'filePath'); | |
}, | |
function (done) { | |
done(null, null); | |
} | |
], function (err, results) { | |
if (err) { | |
throw err; | |
} | |
var idx = some(results, function (i) { return !!i; }); | |
// => 1 | |
if (idx === -1) { | |
throw new Error("File not found"); | |
} | |
console.log('Found file', results[idx]); | |
// => 'filePath' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does the same thing in a less confusing way :P