v1.10.0
This commit is contained in:
parent
f29a8a1b67
commit
773977dd96
10 changed files with 194 additions and 132 deletions
28
lib/caches.js
Normal file
28
lib/caches.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
'use strict';
|
||||
|
||||
let cache = module.exports.cache = new Map();
|
||||
|
||||
module.exports.push = (name, value) => {
|
||||
if (!cache.has(name)) {
|
||||
cache.set(name, []);
|
||||
} else if (!Array.isArray(cache.get(name))) {
|
||||
cache.set(name, [].concat(cache.get(name) || []));
|
||||
}
|
||||
cache.get(name).push(value);
|
||||
};
|
||||
|
||||
module.exports.shift = name => {
|
||||
if (!cache.has(name)) {
|
||||
return false;
|
||||
}
|
||||
if (!Array.isArray(cache.get(name))) {
|
||||
let value = cache.get(name);
|
||||
cache.delete(name);
|
||||
return value;
|
||||
}
|
||||
let value = cache.get(name).shift();
|
||||
if (!cache.get(name).length) {
|
||||
cache.delete(name);
|
||||
}
|
||||
return value;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue