UNPKG

remix-nlux

Version:

Remix IDE NLUX integration. Remix IDE is the leading IDE for building and deploying smart contracts on Ethereum. NLUX is a JavaScript and React library for building conversational AI experiences.

24 lines (20 loc) 643 B
import {NluxError} from '../types/error'; export const throttle = <CallbackType>(callback: CallbackType, limitInMilliseconds: number) => { let waiting = false; if (typeof callback !== 'function') { throw new NluxError({ source: 'x/throttle', message: 'Callback must be a function', }); } const throttled = ((...args: []) => { if (!waiting) { callback.apply(this, args); waiting = true; setTimeout(function () { waiting = false; }, limitInMilliseconds); } }) as CallbackType; return throttled; };