npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

timeout-idle-promise

1.0.0

@gajus

npmHomeRepoSnykSocket
Downloads:20
$ npm install timeout-idle-promise
DailyWeeklyMonthlyYearly

timeout-idle-promise

Travis build status Coveralls NPM version Canonical Code Style Twitter Follow

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);