1.3.0 • Published 8 years ago

promise-timeout v1.3.0

Weekly downloads
49,387
License
MIT
Repository
github
Last release
8 years ago

promise-timeout

A super-simple way to put a timeout on promise resolution.

It assumes you already have either platform support for promises (Node 0.12 or greater), or you have a polyfill (see es6-promise).

Installation

$ npm install promise-timeout

Usage

timeout(promise, timeoutMillis)

Rejects a promise with a TimeoutError if it does not settle within the specified timeout. Parameters:

  • promise: Promise - Promise to monitor.
  • timeoutMillis: number - Number of milliseconds to wait on settling.

TimeoutError

Exception indicating that the timeout expired.

Examples

ES2015:

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

let somePromise = goDoSomething();

timeout(somePromise, 1000)
  .then((thing) => console.log('I did a thing!'))
  .catch((err) => {
    if (err instanceof TimeoutError) {
      console.error('Timeout :-(');
    }
  });

ES5:

'use strict';

var pt = require('promise-timeout');

var somePromise = goDoSomething();

pt.timeout(somePromise, 1000)
  .then(function (thing) {
    console.log('I did a thing!');
  }).catch(function (err) {
    if (err instanceof pt.TimeoutError) {
      console.error('Timeout :-(');
    }
  });
kafka-publisher-ssprolinklisqvizeontology-dapi-testdoc4k_react_uiisv-lynx-devnow-static-build-test@infinitebrahmanuniverse/nolb-promise-@everything-registry/sub-chunk-2481@you54f/pact-cliworking-rcontg4websitevladi-server-corejaidbotjdbc-altibasejhonny-sdkkafka-publisherhomebridge-roomba-stvhomebridge-braavahomebridge-tplink-hs100-lightbulbshomebridge-tplink-lightbulbiobroker.klf200ledger-wallet-providerlimestone-nodelocal-network-scanleancloud-realtimeleancloud-storageklf-200-api@wecity/weda-builder@wongterrencew/now-whitelisted-static-build@truffle/dashboard-provider@tksolution/tks-datasource-api-core@tksolution/tks-graphql-api-core@userbugreport/bugbutton-react@unyxos/working-rcon@vision-dev/cli@vision-design/clialiquammolestiaesuntessezazu-translationverpubvectorcalc@nielinjie/multi-repomongoose-smartcachemintcore-uimixbee-ts-sdkmongodb-stashmeross-cloud-tsontology-dapiontology-dapi-desktopontology-ts-sdkserver-core-cubejssail-toolsprolink-connectpro-util-packagesfcc-schemassfcc-schemas-latestnow-haskell-builderredstone-evm-connectorredstone-noderaml-1-parser-test-utilsrihandjsproxychoosersignalz@olliemurray/cryptosimmod@ont-community/ontology-ts-sdk-ledger@ont-community/ontology-ts-sdk-trezor@ont-dev/ontology-dapi@ont-dev/ontology-ts-sdk-ledger@general-process/now-static-jam@heora/cubejs-server-core@imvision/cli@pact-foundation/pact-cli@ozo/lazy-loaderds-cctalkfeathers-cctalk@protoplan/exchange-rates@chainlink/ea-bootstrap@classapp-tech/prometheus-integrationcheck-proxycheck-proxy-advcheck-proxy-newcctalk-devicescctalkclusterduckclosest-http-endpointcontinuous-streamscryptosimdad-dapidad-ts-sdkcubejs-modified-server-corecubejs-server-corecubejs-backend-server-core-forkcube-server-coreavalanche-videodna-ts-sdk@alan-eu/now-whitelisted-static-build@decentology/dappstarter@cryptosat/cryptosim@cubejs-backend-json-clone/server-core
1.3.0

8 years ago

1.2.0

8 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

10 years ago