3 ms·
It was a short, simple example to illustrate how yield will improve Node. In real life, you'd probably just do something like: fs.readdirSync(dir).map(func
by ggreer 13y ago
It was a short, simple example to illustrate how yield will improve Node. In real life, you'd probably just do something like:
fs.readdirSync(dir).map(function (f) {
return {
name: f,
stat: fs.statSync(path.join(dir, f))
}
}).sort(function (a, b) {
return b.stat.size - a.stat.size;
});
Not going to win any code golf tournaments, but that's JavaScript for you. It was never designed to do this sort of thing. Its strengths lie elsewhere.
- ricardobeat 13y agoIn real life you wouldn't use sync methods, they would destroy your server's performance by blocking the event loop.