Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-deco

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-deco - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

callback/fallback-value.js

5

package.json
{
"name": "async-deco",
"version": "1.0.1",
"version": "1.1.0",
"description": "A collection of decorators you can use to wrap functions (callback or promise based) to make them more robust",

@@ -34,4 +34,5 @@ "main": "index.js",

"es6-promisify": "^3.0.0",
"require-all": "^2.0.0"
"require-all": "^2.0.0",
"setimmediate": "^1.0.4"
}
}

65

README.md
async-deco
==========
[![Build Status](https://travis-ci.org/sithmel/diogenes.svg?branch=master)](https://travis-ci.org/sithmel/diogenes)
This is a collection of function decorators designed to work with functions using a callback or returning a promise.
In case of callback, it must follow the node convention: the callback should be the last argument and its arguments should be, an error instance and the output of the function.
In case of callbacks, it must follow the [node convention](https://docs.nodejitsu.com/articles/errors/what-are-the-error-conventions): the callback should be the last argument and its arguments should be, an error instance and the output of the function.
Most of them are designed to make an asynchronous function call more robust and reliable.

@@ -76,4 +78,4 @@ They can be combined together using the "compose" function (included).

It takes 2 arguments:
* an optional getKey function: when it runs against the original arguments it returns the key used for the caching
* a logger function (logs "cachehit")
* a getKey function [optional]: when it runs against the original arguments it returns the key used for the caching. If it is missing the function memoize the first result and returns always the same.
* a logger function (logs "cachehit") [optional]

@@ -91,4 +93,4 @@ Cache

It takes 2 arguments:
* a cache object. The interface should be compatible with memoize-cache (https://github.com/sithmel/memoize-cache)
* a logger function (logs "cachehit")
* a cache object [mandatory]. The interface should be compatible with memoize-cache (https://github.com/sithmel/memoize-cache)
* a logger function (logs "cachehit") [optional]

@@ -107,6 +109,20 @@ Fallback

It takes 3 arguments:
* fallback function. It takes the err, and the original arguments.
* error instance for deciding to fallback, or a function taking error and result (if it returns true it'll trigger the fallback)
* logger function (logs "fallback")
* fallback function [mandatory]. It takes the err, and the original arguments.
* error instance for deciding to fallback, or a function taking error and result (if it returns true it'll trigger the fallback) [optional, it falls back on any error by default]
* logger function (logs "fallback") [optional]
Fallback value
--------------
If a function fails, returns a value
```js
var fallbackValueDecorator = require('async-deco/callback/fallback-value');
var fallback = fallbackValueDecorator('giving up', Error, logger);
fallback(function (..., cb) { .... });
```
It takes 3 arguments:
* fallback value [mandatory]
* error instance for deciding to fallback, or a function taking error and result (if it returns true it'll trigger the fallback) [optional, it falls back on any error by default]
* logger function (logs "fallback") [optional]
Fallback cache

@@ -122,5 +138,5 @@ --------------

It takes 3 arguments:
* a cache object. The interface should be compatible with memoize-cache (https://github.com/sithmel/memoize-cache)
* error instance for deciding to fallback, or a function taking error and result (if it returns true it'll trigger the fallback)
* logger function (logs "fallback-cache")
* a cache object [mandatory]. The interface should be compatible with memoize-cache (https://github.com/sithmel/memoize-cache)
* error instance for deciding to fallback, or a function taking error and result (if it returns true it'll trigger the fallback) [optional, it falls back on any error by default]
* logger function (logs "fallback-cache") [optional]

@@ -148,8 +164,8 @@ Log

It takes 2 arguments:
* time in ms
* a logger function (logs "timeout")
* time in ms [mandatory]
* a logger function (logs "timeout") [optional]
Retry
-----
If a function fails it retry it again
If a function fails, it retry running it again
```js

@@ -162,7 +178,20 @@ var retryDecorator = require('async-deco/callback/retry');

You can initialise the decorator with 3 arguments:
* number of retries
* interval for trying again (number of a function based on the number of times)
* error instance for deciding to retry, or function taking error and result (if it returns true it'll trigger the retry)
* logger function (logs "retry")
* number of retries [optional, it defaults to Infinity]
* interval for trying again (number of a function based on the number of times) [optional, it defaults to 0]
* error instance for deciding to retry, or function taking error and result (if it returns true it'll trigger the retry) [optional, it falls back on any error by default]
* logger function (logs "retry") [optional]
Limit
-----
Limit the parallel execution of a function.
```js
var limitDecorator = require('async-deco/callback/limit');
var limitToTwo = limitDecorator(2, logger);
limitToTwo(function (..., cb) { .... });
```
You can initialise the decorator with 2 arguments:
* number of parallel execution [mandatory]
* logger function (logs "limit" when a function gets queued) [optional]
Utilities

@@ -169,0 +198,0 @@ =========

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc