Created
June 20, 2012 03:29
-
-
Save vadimtsushko/2957978 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
#import("dart:io"); | |
main(){ | |
int sum = 0; | |
DirectoryLister lister = new Directory("c:\\dropbox").list(true); | |
var filesProcessed = new List<Future>(); | |
lister.onError = (e) { throw e; }; | |
lister.onFile = (String file) { | |
// print("File: $file"); | |
// Please ignore the length() vs lengthSync(), because my | |
// actual use case is a longer IO operation, e.g. DB call. | |
Future f = new File(file).length(); | |
filesProcessed.add(f); | |
f.then((int c) { | |
sum += c; | |
//print(" - sum: $sum ($file)"); | |
}); | |
}; | |
lister.onDone = (bool success) { | |
Futures.wait(filesProcessed).then((_) { | |
print("Final sum: $sum"); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment