asynchrony
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -7,3 +7,3 @@ { | ||
"name": "asynchrony", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Auto unwrap promise parameters for clean asynchronous code", | ||
@@ -10,0 +10,0 @@ "repository": { |
@@ -8,30 +8,12 @@ # asynchrony | ||
### Comparison with Promises Code | ||
### Installation | ||
Code without asynchrony. | ||
``` | ||
/* | ||
Example taken from https://blog.domenic.me/youre-missing-the-point-of-promises/ | ||
Implementation of getTweetsFor(), parseTweetsForUrls() etc removed for brevity | ||
*/ | ||
npm install asynchrony | ||
getTweetsFor("domenic") | ||
.then(function (tweets) { | ||
var shortUrls = parseTweetsForUrls(tweets); | ||
var mostRecentShortUrl = shortUrls[0]; | ||
return expandUrlUsingTwitterApi(mostRecentShortUrl); // promise-returning function | ||
}) | ||
.then(httpGet) // promise-returning function | ||
.then( | ||
function (responseBody) { | ||
console.log("Most recent link text:", responseBody); | ||
}, | ||
function (error) { | ||
console.error("Error with the twitterverse:", error); | ||
} | ||
); | ||
``` | ||
### Comparison with Promises Code | ||
Code with asynchrony. See how functions are wrapped in asynchrony. | ||
``` | ||
var asynchrony = require('asynchrony'); | ||
//Get tweets for a handle | ||
@@ -80,2 +62,3 @@ var getTweetsFor = asynchrony(function(name) { | ||
//Look ma, not many then()s! | ||
var tweets = getTweetsFor("jeswin"); | ||
@@ -93,1 +76,25 @@ var shortUrls = parseTweetsForUrls(tweets); | ||
``` | ||
Code without asynchrony. | ||
``` | ||
/* | ||
Example taken from https://blog.domenic.me/youre-missing-the-point-of-promises/ | ||
Implementation of getTweetsFor(), parseTweetsForUrls() etc removed for brevity | ||
*/ | ||
getTweetsFor("domenic") | ||
.then(function (tweets) { | ||
var shortUrls = parseTweetsForUrls(tweets); | ||
var mostRecentShortUrl = shortUrls[0]; | ||
return expandUrlUsingTwitterApi(mostRecentShortUrl); // promise-returning function | ||
}) | ||
.then(httpGet) // promise-returning function | ||
.then( | ||
function (responseBody) { | ||
console.log("Most recent link text:", responseBody); | ||
}, | ||
function (error) { | ||
console.error("Error with the twitterverse:", error); | ||
} | ||
); | ||
``` |
41323
98