3
3
// Facade that wraps Map and Node.js Timers to provide a simple interface for a
4
4
// collection with values that have expiration timeout.
5
5
6
- const TimeoutCollection = function ( timeout ) {
6
+ const TimeoutCollection = function ( timeout ) {
7
7
this . timeout = timeout ;
8
8
this . collection = new Map ( ) ;
9
9
this . timers = new Map ( ) ;
10
10
} ;
11
11
12
- TimeoutCollection . prototype . set = function ( key , value ) {
12
+ TimeoutCollection . prototype . set = function ( key , value ) {
13
13
const timer = this . timers . get ( key ) ;
14
14
if ( timer ) clearTimeout ( timer ) ;
15
15
const timeout = setTimeout ( ( ) => {
@@ -20,11 +20,11 @@ TimeoutCollection.prototype.set = function(key, value) {
20
20
this . timers . set ( key , timeout ) ;
21
21
} ;
22
22
23
- TimeoutCollection . prototype . get = function ( key ) {
23
+ TimeoutCollection . prototype . get = function ( key ) {
24
24
return this . collection . get ( key ) ;
25
25
} ;
26
26
27
- TimeoutCollection . prototype . delete = function ( key ) {
27
+ TimeoutCollection . prototype . delete = function ( key ) {
28
28
const timer = this . timers . get ( key ) ;
29
29
if ( timer ) {
30
30
clearTimeout ( timer ) ;
@@ -33,7 +33,7 @@ TimeoutCollection.prototype.delete = function(key) {
33
33
}
34
34
} ;
35
35
36
- TimeoutCollection . prototype . toArray = function ( ) {
36
+ TimeoutCollection . prototype . toArray = function ( ) {
37
37
return [ ...this . collection . entries ( ) ] ;
38
38
} ;
39
39
@@ -54,5 +54,4 @@ setTimeout(() => {
54
54
hash . set ( 'quattro' , 4 ) ;
55
55
console . dir ( { array : hash . toArray ( ) } ) ;
56
56
} , 500 ) ;
57
-
58
57
} , 1500 ) ;
0 commit comments