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

cached-callback

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cached-callback - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

14

index.js

@@ -43,5 +43,6 @@ /* global define */

case 0: cb(); break
case 1: cb(a[0], a[1]); break
case 2: cb(a[0], a[1], a[2]); break
case 3: cb(a[0], a[1], a[2], a[3]); break
case 1: cb(a[0]); break
case 2: cb(a[0], a[1]); break
case 3: cb(a[0], a[1], a[2]); break
case 4: cb(a[0], a[1], a[2], a[3]); break
default: cb.apply(null, a)

@@ -63,2 +64,9 @@ }

cachedCallback.cache = function configureCache (cacher) {
if (typeof cacher === 'undefined') cacher = true
return function cachedCallbackWithCache (getter) {
return cachedCallback(getter, cacher)
}
}
if (typeof exports === 'object') {

@@ -65,0 +73,0 @@ module.exports = cachedCallback

{
"name": "cached-callback",
"version": "2.0.0",
"version": "2.1.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -43,2 +43,10 @@ # cached-callback

The second `cache` argument is also exposed with `.cache()`
```js
var cached = require('cached-callback').cache()
var get = cached(function (id, callback) {
request('http://example.com/'+id, callback)
}
```
### Custom caching method

@@ -45,0 +53,0 @@ Caches the result with a custom caching method.

@@ -51,2 +51,14 @@ var assert = require('assert')

// test debounce when no key is used
var called = 0
var without = debounce(function (cb) {
setTimeout(function () { cb(++called) }, 1)
})
without(function (val) { assert.equal(val, 1) })
without(function (val) { assert.equal(val, 1) })
setTimeout(function () {
without(function (args) { assert.equal(args, 2) })
}, 2)
//

@@ -72,4 +84,18 @@ // Check cache

// test cache setter cachedCallback.cache(true)
// test caching when no key is passed
var cachedCallback = require('./').cache(true)
var times = 0
var persistent = cachedCallback(function (cb) {
setTimeout(function () { cb(++times) }, 1)
})
persistent(function (val) { assert.equal(val, 1) })
persistent(function (val) { assert.equal(val, 1) })
setTimeout(function () {
persistent(function (val) { assert.equal(val, 1) })
}, 2)
process.on('exit', function (exitCode) {
if (!exitCode) console.log('All tests succeeded.')
})
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