Created
November 13, 2012 18:04
-
-
Save ritch/4067355 to your computer and use it in GitHub Desktop.
AwaitScript
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
// the way you want to do it | |
var files = []; | |
function recurse(dir) { | |
dir.forEach(function (f) { | |
if(stat(f).isFile()) { | |
files.push(f); | |
} else { | |
recurse(fs.readdir(dir)); | |
} | |
}); | |
} | |
try { | |
recurse(fs.readdir('.')); | |
} catch(e) { | |
console.error(e); | |
} | |
// the magic way that could maybe work with await | |
var files = []; | |
function recurse(dir) { | |
(await dir).forEach(function (f) { | |
if((await stat(f)).isFile()) { | |
files.push(f); | |
} else { | |
recurse(fs.readdir(dir)); | |
} | |
}); | |
} | |
async try { | |
recurse(fs.readdir('.')); | |
} catch(e) { | |
// same scope, not same tick | |
console.error(e); | |
} finally { | |
console.log('and done...'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment