1.0.2 • Published 5 years ago

@gfxpulse/timeout-map v1.0.2

Weekly downloads
49
License
ISC
Repository
github
Last release
5 years ago

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

OptionTypeDefaultDescription
autodeletebooltrueKey automatically deleted from map before handler is called
timeoutintnullHow long until handler is called (null = never)
marginint0Minimum time interval between set of handler calls
additional_argumentsarray[]Additional arguments passed to handler
handlerFunction(key, value, map) => {}Function called after timeout. Key, value, map and additional arguments are passed as parameters