Skip to content

Instantly share code, notes, and snippets.

@refractalize
Created September 23, 2012 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refractalize/3770212 to your computer and use it in GitHub Desktop.
Save refractalize/3770212 to your computer and use it in GitHub Desktop.
Pogo's async operator, `!`
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"
three: 4128
one: 4630
two: 3130
3 files in total
@refractalize
Copy link
Author

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 to fs.stat().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment