npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@instaffogmbh/promise-timeout-with-warning

v0.1.15

Published

Limit how long to wait for a promise to resolve, with optional earlier warning.

Downloads

62

Readme

@instaffogmbh/promise-timeout-with-warning

Limit how long to wait for a promise to resolve, with optional earlier warning.

API

This module exports one function:

ptww(origPr[, opts])

Returns a promise tmoPr that reflects origPr's resolution or, if that takes too long, is rejected with a timeout error.

origPr can be any value, e.g. a promise. If it's not already a promise, ptww will instead use a new promise resolved with that value.

opts is an optional options object that supports these keys:

  • warn, fail: Each either strings with a human-readable timeout specification like "30 sec", or false to deactivate that feature.
  • unwatched: If warn and fail are both deactivated (i.e. no timers would be installed) and unwatched is set to sth. other than undefined, immediately return unwatched instead of dealing with any promise logic.
  • autostart: If set to false, ptww won't start the timers immediately.
  • logger: An console-like object to use for logging. Default: console
  • warnMsg: A message to be logged when the warn timeout has elapsed.
  • failMsg: Error message for the timeout promise rejection.
  • msg: A message describing what still not happened yet. Used to extemporize warnMsg and/or failMsg if they're missing.
  • descr: If no msg was provided, extemporize one from this noun.
  • startMsg: If true-y, log this message when timers are (re-)started. Boolean true = extemporize from msg.
  • doneMsg: If true-y, log this message when origPr solves duly. Boolean true = extemporize from msg.
  • vErr: If set, msg must be a non-empty string.
    • true: wrap any rejections except TimeoutError in a VError using msg.
    • "announce": like true but also extemporize startMsg and doneMsg in case they're false-y.
  • errorSubj: If true-y, prefix non-timeout error messages with this topic/context description and ': '.
  • subj: Like errorSubj but also affects the …Msg option values.
  • subjSuffix: In case subj is used and this is neither set to the empty string nor false, put this between subj and the message. (Does not affect errorSubj.) Defaults to ': ' (a colon and a space).

tmoPr will expose these additional methods:

  • ifWatching(): Returns tmoPr if any of the timers is currently installed, or false otherwise.
  • reset(): Restart both timers. If you were warned already, you might be warned again.
  • unTimeout(): Uninstall and abandon both timers. You can install new ones with .reset(). Returns tmoPr.

 

License

MIT