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 🙏

© 2025 – Pkg Stats / Ryan Hefner

resettable-defer

v1.0.0

Published

Like a reusable Promise.defer, where you subscribe to the next resolve

Readme

resettable-defer

For when you need a Promise.defer, but you need to use it more than once, eg. because there is some code that needs to subscribe whatever the next (periodic) 'activation' is.

It's kind of like an EventEmitter with a single event, but less hassle to use with Promises.

Example

const resettableDefer = require("resettable-defer");

let defer = resettableDefer({ autoReset: true });

/* The below configuration of intervals should result in approximately 5 instances
   of "Activated!" getting logged at once, every half a second, forever. */

setInterval(async () => {
	await defer.await();
	console.log("Activated!");
}, 100);

setInterval(async () => {
	defer.resolve();
}, 500);

API

defer = resettableDefer(options)

Creates a new resettable defer. Options:

  • autoReset: Defaults to false. Automatically 'reset' the defer once it resolves or rejects.
    • When false: if you defer.await() after the defer has already settled, it will immediately settle with the existing result, and you need to call defer.reset() manually to use it again.
    • When true: after the defer settles, it is automatically reset, and can immediately be used again; the next defer.await() calls will track a new internal defer.

defer.await()

Returns a Promise that resolves or rejects when (the current instance of) the defer does. This is the equivalent of the defer.promise property that you will find in most defer implementations, but here it is a function instead of just a static property.

If (the current instance of) the defer is already resolved or rejected, then the returned Promise will also be immediately resolved or rejected, ie. the results are essentially cached.

defer.resolve(value)

Resolves the defer (and all Promises tracking it) with the specified value.

defer.reject(error)

Rejects the defer (and all Promises tracking it) with the specified error, which should be an Error instance or subclass.

defer.track(promise)

Causes the defer to track an externally-provided promise; when that Promise resolves or rejects, so will the defer and all Promises tracking it.

defer.reset()

'Resets' the defer, so that it can be used anew. Note that if you have one or more Promises tracking the previous instance, and that instance hadn't settled yet, these Promises will never resolve!