delay

JavaScript, Function

Invokes the provided function after ms milliseconds.

  • Use setTimeout() to delay execution of fn.
  • Use the spread (...) operator to supply the function with an arbitrary number of arguments.
const delay = (fn, ms, ...args) => setTimeout(fn, ms, ...args);
delay(
  function(text) {
    console.log(text);
  },
  1000,
  'later'
); // Logs 'later' after one second.

Recommended snippets

  • debouncePromise

    JavaScript, Function

    Creates a debounced function that returns a promise, but delays invoking the provided function until at least ms milliseconds have elapsed since the last time it was invoked. All promises returned during this time will return the same data.

  • debounce

    JavaScript, Function

    Creates a debounced function that delays invoking the provided function until at least ms milliseconds have elapsed since the last time it was invoked.

  • throttle

    JavaScript, Function

    Creates a throttled function that only invokes the provided function at most once per every wait milliseconds