Created
November 12, 2014 14:49
-
-
Save anodynos/2e113eace0001a4a5748 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
// See https://github.com/cujojs/when/issues/403 | |
// Generated by CoffeeScript 1.8.0 | |
var When, arrayItems, catchCount, esprima, expand, file, fileTxt, files, fs, i, jspath, path, readFileP, _i, _j, _len; | |
fs = require('fs'); | |
When = require('when'); | |
When.node = require('when/node'); | |
When.sequence = require('when/sequence'); | |
readFileP = When.node.lift(fs.readFile); | |
path = require('path'); | |
expand = require('glob-expand'); | |
esprima = require('esprima'); | |
jspath = '../node_modules/lodash'; | |
arrayItems = []; | |
for (i = _i = 1; _i <= 1000; i = ++_i) { | |
arrayItems.push((function(i) { | |
return function() { | |
return When(i); | |
}; | |
})(i)); | |
} | |
fileTxt = null; | |
files = expand({ | |
cwd: jspath, | |
filter: 'isFile' | |
}, ['**/*.js']); | |
for (_j = 0, _len = files.length; _j < _len; _j++) { | |
file = files[_j]; | |
fileTxt = fs.readFileSync(path.join(jspath, file), 'utf8'); | |
esprima.parse(fileTxt); | |
console.log("test parsing file is ok `" + file + "`"); | |
} | |
catchCount = 0; | |
When.iterate(function(i) { | |
return i + 1; | |
}, function(i) { | |
return !(i < arrayItems.length); | |
}, function(i) { | |
var item; | |
item = arrayItems[i]; | |
return When.iterate(function(j) { | |
return j + 1; | |
}, function(j) { | |
return !(j < files.length); | |
}, function(j) { | |
var p; | |
file = files[j]; | |
p = When.sequence([ | |
function() { | |
return item().then(function(v) { | |
return When(v).delay(1).then(function(v) { | |
console.log("#" + v + " reading file with promise: `" + file + "`"); | |
return readFileP(path.join(jspath, file), 'utf8').then(function(res) { | |
return fileTxt = res; | |
}); | |
}); | |
}); | |
}, function() { | |
return item().then(function(v) { | |
return When(v).delay(1).then(function(v) { | |
var ast, _k; | |
console.log("#" + v + " parsing file: `" + file + "`"); | |
for (i = _k = 1; _k <= 10; i = ++_k) { | |
ast = esprima.parse(fileTxt); | |
} | |
return console.log(fileTxt.slice(1, 101), ast.type); | |
}); | |
}); | |
} | |
]); | |
console.log('registering catch #', catchCount++); | |
return p["catch"](function(err) { | |
l.error("An error was caught:", err); | |
return process.exit(1); | |
}); | |
}, 0); | |
}, 0); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment