Function ignore

A function that executes a callback and ignores it completely, if it throws an error, returns any value, rejects a promise - it will be all ignored. It will attach a catch handler to any returned promise to avoid unhandled rejections.

Use it whenever you want to call a function, but you are not interested in its result or failure.

import { trackPageVisit } from "analytics-service";

function onButtonClick() {
ignore(() => trackPageVisit("button-click"));
// ^ prevent uncaught errors or unhandled promise rejections from trackPageVisit
}
Promise.resolve(5).then(ignore(trackPageVisit)).then((value) => {
console.log(value); // 5, won't ever crash due to errors in trackPageVisit
});
  • Parameters

    • callback: () => unknown

    Returns undefined