Skip to content

Instantly share code, notes, and snippets.

@vadimtsushko
Created June 20, 2012 03:29
Show Gist options
  • Save vadimtsushko/2957978 to your computer and use it in GitHub Desktop.
Save vadimtsushko/2957978 to your computer and use it in GitHub Desktop.
#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