1.0.1 • Published 5 years ago

@gfxpulse/timeout-set v1.0.1

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

Install

npm install @gfxpulse/timeout-set

Example

const TimeoutSet = require('@gfxpulse/timeout-set');

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

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

Output:

value1 - some argument
value1 in set - false
value2 - some argument
value2 in set - true

Options

OptionTypeDefaultDescription
autodeletebooltrueValue automatically deleted from set 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(value, set) => {}Function called after timeout. Value, set and additional arguments are passed as parameters