timeout-idle-promise

Detects when a promise is idle (does not create asynchronous events) for longer than permitted amount of time.

OTHER License

Downloads
43
Stars
9
Committers
1

timeout-idle-promise

Detects when a promise is idle (does not create asynchronous events) for longer than permitted amount of time.

API

import {
  timeoutIdlePromise,
  TimeoutError,
} from 'timeout-idle-promise';

/**
 * @param {Function} promiseFactory
 * @param {number} maximumIdleTime Idle timeout in milliseconds.
 * @throws TimeoutError
 */
timeoutIdlePromise(promiseFactory);

Example Usage

// Rejected with Idle promise timeout.
timeoutIdlePromise(() => {
  return new Promise((resolve) => {

  });
}, 1000);

// Resolved.
timeoutIdlePromise(() => {
  return new Promise((resolve) => {
    setTimeout(() => {
      setTimeout(() => {
        setTimeout(() => {
          resolve();
        }, 500);
      }, 500);
    }, 500);
  });
}, 1000);