Enhance Promise Functionality with p-timeout and promise.timeout Libraries


Summary of my bookmarked Github repositories from Nov 23rd, 2016

Github repositories

  • sindresorhus/p-timeout

    p-timeout is a JavaScript library that allows you to set a timeout for a promise. It provides a decorator for promises that times them out after a specified number of milliseconds. The library offers various options for customization, including setting a custom error message, specifying fallback actions, using custom timers for testing purposes, and aborting the promise using AbortController. It also exposes the TimeoutError class for checking and subclassing. If you need to handle promises with timeouts in your code, p-timeout can be a useful tool to consider.

  • magicdawn/promise.timeout

    The 'promise.timeout' module allows you to add timeout support for async functions in an ES5 environment. It requires the global 'AbortController', which is built-in in Node.js since version 15. The module provides the 'ptimeout' function, which takes an async function and a timeout value in milliseconds. If the function exceeds the specified timeout, it throws a 'TimeoutError' with details about the timeout. You can also use the 'signal' argument to register abort actions when the timeout is reached. The module offers an alternative to using the 'AbortController' package.