Created
September 23, 2012 12:12
-
-
Save refractalize/3770212 to your computer and use it in GitHub Desktop.
Pogo's async operator, `!`
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
fs = require 'fs' | |
filenames = fs.readdir! '.' | |
stats = [f <- filenames, size = fs.stat (f)!.size, {filename = f, size = size}] | |
for each @(stat) in (stats) | |
console.log "#(stat.filename): #(stat.size)" | |
console.log () | |
console.log "#(filenames.length) files in total" |
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
three: 4128 | |
one: 4630 | |
two: 3130 | |
3 files in total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script makes for a simple (unix) ls command, but examines the file stats concurrently.
The script uses a combination of list comprehensions and the async operator
!
to make concurrent calls tofs.stat()
.