npm.io
1.0.2 • Published 6 years ago

@gfxpulse/timeout-map

Licence
ISC
Version
1.0.2
Deps
0
Size
4 kB
Vulns
0
Weekly
0

Install

npm install @gfxpulse/timeout-map

Example

const TimeoutMap = require('@gfxpulse/timeout-map');

let map = new TimeoutMap([['key1', 'value1']], {
    autodelete: true,
    timeout: 5000,
    margin: 100,
    additional_arguments: ['some argument'],
    handler: function (key, value, map, additional_argument1) {
        console.log(`${key}: ${value} - ${additional_argument1}`);
        console.log(`${key} in map - ${map.has(key)}`);
    }
});

map.set('key2', 'value2', {
    autodelete: false,
});

Output:

key1: value1 - some argument
key1 in map - false
key2: value2 - some argument
key2 in map - true

Options

Option Type Default Description
autodelete bool true Key automatically deleted from map before handler is called
timeout int null How long until handler is called (null = never)
margin int 0 Minimum time interval between set of handler calls
additional_arguments array [] Additional arguments passed to handler
handler Function (key, value, map) => {} Function called after timeout. Key, value, map and additional arguments are passed as parameters

Keywords