Skip to content

Instantly share code, notes, and snippets.

@al6x
Created August 24, 2012 07:55
Show Gist options
  • Save al6x/3447276 to your computer and use it in GitHub Desktop.
Save al6x/3447276 to your computer and use it in GitHub Desktop.
Simplifying async call pattern with forking
commit = =>
@exec 'git', ['add', '.'], {}, null, (err) =>
return callback err if err
@exec 'git', ['commit', '-am', 'upd'], {}, null, (err, data) =>
return callback err if err
@head (err, sha) ->
return callback err if err
callback null, sha
commit = =>
@exec 'git', ['add', '.'], {}, null, fork callback, =>
@exec 'git', ['commit', '-am', 'upd'], {}, null, fork callback, (data) =>
@head fork callback, (sha) ->
callback null, sha
@@ -19,8 +20,7 @@ createParentDirs = (base, path, callback) ->
if exists
checkNext()
else
- fs.mkdir path, (err) ->
- return callback err if err
+ fs.mkdir path, fork callback, ->
checkNext()
checkNext()
@@ -33,17 +33,14 @@ deleteParentDirs = (base, path, callback) ->
return callback null if index == paths.length
path = base + '/' + paths[0..(path.length - index - 1)].join('/')
index += 1
- fs.readdir path, (err, list) ->
- return callback err if err
+ fs.readdir path, fork callback, (list) ->
if list.length == 0
- fs.rmdir path, (err) ->
- return callback err if err
+ fs.rmdir path, fork callback, ->
checkNext()
else
callback()
checkNext()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment