Created
August 28, 2013 18:36
-
-
Save mparke/6369605 to your computer and use it in GitHub Desktop.
Chaining functions together for async work
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
function createLinkGetter(linkProcessFn) { | |
return function(url) { | |
asyncFetch(url, linkProcessFn); | |
}; | |
} | |
function createLinkProcessor(fetchPageFn) { | |
return function(links) { | |
for(var i = 0; i < links.length; i++) { | |
fetchPageFn(links[i]); | |
} | |
}; | |
} | |
function fetchPage(url) { | |
// do final step | |
} | |
var linkProcessor = createLinkProcessor(fetchPage); | |
var linkGetter = createLinkGetter(linkProcessor); | |
linkGetter('http://'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment