Skip to content

Execute multiple function calls in a timeout amount of time just once

License

Notifications You must be signed in to change notification settings

mature-woman/damper.mjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Damper (debouncer, демпфер)

Execute multiple function calls in a timeout amount of time just once

You may also know this technology as a "debouncer" (you are free to use any name)
I prefer "damper", from the word "демпфер"

Example

const dampered = damper(
    (
        a,              // 0
        b,              // 1
        c,              // 2
        force = false,  // 3
        d,              // 4
        resolve,
        reject
    ) => {},
    500,
    3,                  // 3 -> the "force" argument
);
 
dampered('for a', 'for b', 'for c', true, 'for d'); // Enabled forced execution