Created
August 24, 2012 07:55
-
-
Save al6x/3447276 to your computer and use it in GitHub Desktop.
Simplifying async call pattern with forking
This file contains 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
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 |
This file contains 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
commit = => | |
@exec 'git', ['add', '.'], {}, null, fork callback, => | |
@exec 'git', ['commit', '-am', 'upd'], {}, null, fork callback, (data) => | |
@head fork callback, (sha) -> | |
callback null, sha |
This file contains 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
@@ -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