"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.promiseTimeout = void 0;

/**
 * @param {{
 *   timeout: number
 *   promise: Promise<any>
 *   shouldReject: boolean
 * }} opts
 * @returns
 */
const promiseTimeout = ({
  timeout,
  promise,
  shouldReject = true
}) => Promise.race([promise, new Promise((resolve, reject) => {
  const id = setTimeout(() => {
    clearTimeout(id);
    shouldReject ? reject() : resolve();
  }, timeout);
})]);

exports.promiseTimeout = promiseTimeout;