Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promto

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promto

Create a promise with timeout

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

promto

npm version

Promise with timeout.

promto(promise:Promise, timeout:number, description: string): Promise

Create a promise which should timeout after N milliseconds. It will be resolved with promise value or rejected with promise error when not timed out, and rejected with timeout error otherwise.

Timeout rejection

const promto = require('promto')

const promise = new Promise(resolve => setTimeout(resolve, 200))
const promiseWithTimeout = promto(promise, 100, 'Example Promise')

promiseWithTimeout.then(console.log, console.error)
// Error: Example Promise has timed out after 100ms

Resolve value

const promto = require('promto')

const promise = new Promise(resolve => setTimeout(
    () => resolve('Promise Result'),
    50
))
const promiseWithTimeout = promto(promise, 100, 'Example Promise')

promiseWithTimeout.then(console.log, console.error)
// Promise Result

Rejection error

const promto = require('promto')

const promise = Promise.reject(new Error('Promise Error'))
const promiseWithTimeout = promto(promise, 100, 'Example Promise')

promiseWithTimeout.then(console.log, console.error)
// Error: Promise Error

2017, Sobesednik Media

Keywords

FAQs

Package last updated on 14 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc