Comparing version 5.2.4 to 5.3.0
"use strict"; | ||
var defer = require('../promise/defer'); | ||
module.exports = function(fn, ctx) { | ||
var running = false; | ||
var wait = null; | ||
return async function () { | ||
var args = [].slice.call(arguments); | ||
if(running) | ||
throw "Already running !"; | ||
if(wait) | ||
return wait; | ||
running = true; | ||
try { | ||
wait = defer(); | ||
var res = await fn.apply(ctx || this, args); | ||
wait.resolve(res); | ||
return res; | ||
} catch(err) { | ||
wait.reject(err); | ||
throw err; | ||
} finally { | ||
running = false; | ||
wait = null; | ||
} | ||
}; | ||
}; |
@@ -12,3 +12,3 @@ "use strict"; | ||
function convertToken(date, token) { | ||
switch (token) { | ||
switch(token) { | ||
case 'E': | ||
@@ -15,0 +15,0 @@ return getSeason(date); |
@@ -7,12 +7,24 @@ "use strict"; | ||
module.exports = function(fn) { | ||
module.exports = function(fn, timeout = 3600 * 1000, gc_interval = 1) { | ||
var cache = {}; | ||
var last_call = Date.now(); | ||
return function(arg) { | ||
if(Date.now() - last_call > timeout / gc_interval) { | ||
last_call = Date.now(); | ||
for(var k of Object.keys(cache)) { | ||
if(cache[k].expires < last_call) | ||
delete cache[k]; | ||
} | ||
} | ||
if(arg in cache) | ||
return cache[arg]; | ||
return cache[arg].value; | ||
cache[arg] = fn.apply(this, arguments); | ||
return cache[arg]; | ||
cache[arg] = {expires : Date.now() + timeout, value : fn.apply(this, arguments)}; | ||
return cache[arg].value; | ||
}; | ||
}; |
{ | ||
"name": "nyks", | ||
"version": "5.2.4", | ||
"version": "5.3.0", | ||
"description": "nodejs exupery style", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -314,4 +314,4 @@ # Async | ||
* [131](https://github.com/131) | ||
* not dependant upon, yet relying on [co](https://github.com/tj/co) | ||
* inspired from the excellent [async](https://github.com/caolan/async) | ||
* Derived from [async-co](https://github.com/131/async-co) | ||
@@ -318,0 +318,0 @@ ------ |
@@ -12,2 +12,3 @@ # Motivation | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT) | ||
[![Code style](https://img.shields.io/badge/code%2fstyle-ivs-green.svg)](https://www.npmjs.com/package/eslint-plugin-ivs) | ||
@@ -14,0 +15,0 @@ |
@@ -13,3 +13,3 @@ "use strict"; | ||
if(i >= len) return x; | ||
switch (x) { | ||
switch(x) { | ||
case '%s': return String(args[i++]); | ||
@@ -16,0 +16,0 @@ case '%d': return Number(args[i++]); |
@@ -78,3 +78,3 @@ "use strict"; | ||
switch (match[8]) { | ||
switch(match[8]) { | ||
case "b": | ||
@@ -81,0 +81,0 @@ arg = arg.toString(2); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62099
1562
52