Socket
Socket
Sign inDemoInstall

asynchrony

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

2

package.json

@@ -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);
}
);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc