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 🙏

© 2026 – Pkg Stats / Ryan Hefner

teepromise

v0.1.2

Published

TeePromise is a very simple utility subclass that makes promises more convenient to use in some situations by exposing `resolve` and `reject` on the promise object itself.

Readme

TeePromise

TeePromise is a very simple utility subclass that makes promises more convenient to use in some situations by exposing resolve and reject on the promise object itself.

const tp = new TeePromise();

tp.resolve(5);                // resolve a value
tp.reject(new Error('oops')); // reject a value
await tp;                     // await a value

Some use cases include:

  • Multiple callbacks already might call resolve and reject, and adding another callback to pass to the Promise constructor would make the code more difficult to read.
  • A method is adding an entry to a job queue and then returning with results when the job is completed. You can include the TeePromise in your job entry and also return it.

Shortcomings:

  • Could be seen as violating the interface segregation principle if you're passing a TeePromise to code that only uses the resolve, reject, or then. This could be mitigated in typescript applications by creating interfaces including only the reject and resolve methods, which conventionally would be named IResolver and IRejecter.

Compared with Promise.withResolvers():

Promise.withResolvers() - you get the promise, and separately resolve and reject.

const { promise, resolve } = Promise.withResolvers();
doSomethingAsync(value => resolve(value));
return promise;

TeePromise - you get a thenable which also implements resolve and reject.

const tp = new TeePromise();
doSomethingAsync(value => tp.resolve(value));
return tp;

Use Cases

Queue

In the implementation of a job queue, TeePromise makes it convenient to include resolve in an entry of the queue without introducing any unnecessary Promise constructor.

class SomeQueueMananger {

    // ...

    print (document) {
        const tp = new TeePromise();
        this.entries.push({
            ...entry,
            donePrinting: printCompletionInfo => {
                tp.resolve(printCompletionInfo);
            },
        });
        
        return tp;
    }
}

Dialog or modal

When a component must return a promise that is resolved or rejected only when the user acts (e.g. clicks OK or Cancel), TeePromise keeps the API simple.

function confirm (message) {
    const tp = new TeePromise();
    showModal({
        message,
        onOk: () => tp.resolve(true),
        onCancel: () => tp.resolve(false),
    });
    return tp;
}

Timeout or abort

TeePromise is useful when you need to reject a promise from outside, for example when implementing a timeout or an abort signal.

function withTimeout (promise, ms) {
    const tp = new TeePromise();
    promise.then(tp.resolve, tp.reject);
    const id = setTimeout(() => tp.reject(new Error('timeout')), ms);
    tp.then(() => clearTimeout(id), () => clearTimeout(id));
    return tp;
}

Callback-to-promise bridge

When wrapping a callback-based API, you can avoid the Promise constructor and pass resolve and reject directly into the callback.

function readFile (path) {
    const tp = new TeePromise();
    fs.readFile(path, (err, data) => {
        if (err) tp.reject(err);
        else tp.resolve(data);
    });
    return tp;
}