Created
January 8, 2010 05:33
-
-
Save isaacs/271878 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 posix = require("posix"), | |
print = require("sys").puts, | |
successes = {}, | |
// number of files to inspect on each pass | |
N = 10, | |
// degree of concurrency | |
C = 5, | |
// print lots of stuff, or just a little? | |
verbose = true, | |
// use a timeout, or call synchronously | |
doTimeout = false; | |
for (var i = 0; i < C; i ++) statLoop(i); | |
function success (i) { return function () { | |
print("=== success "+i); | |
delete(successes[i]); | |
var fail = false; | |
for (var k in successes) { | |
return; | |
} | |
print("IT WORKED!!"); | |
}}; | |
function statLoop (i) { | |
successes[i] = false; | |
var j = i * N; | |
statLoopInner(); | |
function done () { | |
if (verbose) print("||| done "+j); | |
var fn = (j < ((i+1)*N)) ? statLoopInner : success(i); | |
if (doTimeout) setTimeout(fn); | |
else fn(); | |
}; | |
function statLoopInner () { | |
j++; | |
if (verbose) print("<<< open "+j); | |
posix.stat("file-" + j).addErrback(done).addCallback(done) | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment