Skip to content

Instantly share code, notes, and snippets.

@jashkenas
Created December 22, 2010 00:57
Show Gist options
  • Save jashkenas/750910 to your computer and use it in GitHub Desktop.
Save jashkenas/750910 to your computer and use it in GitHub Desktop.
for f, index in files
extname = path.extname f
fs.lstat f, (err, stats) ->
if !stats.isDirectory() and extname is '.coffee'
fs.readFile f, 'utf8', compileCallback
else if stats.isDirectory()
readDirAfterThisOne = ->
if index is files.length - 1 then clearInterval(h) and processDir(f)
h = setInterval readDirAfterThisOne, 50
# In order for this to work reliably, f and extname would have to be captured, but index would have
# to *not* be captured, so that the readDirAfterThisOne closure can work. Here's how this would be
# written with the proposed `do` syntax:
for f, index in files
extname = path.extname f
do (f, extname) ->
fs.lstat f, (err, stats) ->
if !stats.isDirectory() and extname is '.coffee'
fs.readFile f, 'utf8', compileCallback
else if stats.isDirectory()
readDirAfterThisOne = ->
if index is files.length - 1 then clearInterval(h) and processDir(f)
h = setInterval readDirAfterThisOne, 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment