mirror of
https://github.com/amark/gun.git
synced 2025-07-29 23:03:19 +00:00
26 lines
567 B
JavaScript
26 lines
567 B
JavaScript
|
|
var Type = require('./type');
|
|
function Dup(opt){
|
|
var dup = {s:{}};
|
|
opt = opt || {max: 1000, age: 1000 * 60 * 2};
|
|
dup.check = function(id){
|
|
return dup.s[id]? dup.track(id) : false;
|
|
}
|
|
dup.track = function(id){
|
|
dup.s[id] = time_is();
|
|
if(!dup.to){
|
|
dup.to = setTimeout(function(){
|
|
Type.obj.map(dup.s, function(time, id){
|
|
if(opt.age > (time_is() - time)){ return }
|
|
Type.obj.del(dup.s, id);
|
|
});
|
|
dup.to = null;
|
|
}, opt.age);
|
|
}
|
|
return id;
|
|
}
|
|
return dup;
|
|
}
|
|
var time_is = Type.time.is;
|
|
module.exports = Dup;
|
|
|