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

wait-for-me-ts

v1.0.1

Published

The high-performance core engine for declarative async error handling in TypeScript.

Readme

⚡ wait-for-me-ts

The high-performance core engine for declarative async error handling in TypeScript. Stop nesting try/catch and start writing linear "Happy Path" code.


🏗️ The "Big Three" Derivatives

For 90% of use cases, these pre-configured utilities provide the cleanest syntax.

1. valueOf<T>

Returns the data or false on failure.

  • Best for: Standard data fetching where false isn't a valid piece of data.
  • Signature: async function valueOf<T>(promise: Promise<T>, config?: LogConfig): Promise<T | false>
const user = await valueOf(fetchUser(1), "User not found");
if (!user) return; 
console.log(user.name);

2. isSuccess

Returns a simple boolean.

  • Best for: Fire-and-forget actions or simple validation.
  • Signature: async function isSuccess(promise: Promise<any>, config?: LogConfig): Promise<boolean>
if (await isSuccess(db.users.delete(id), { success: "Deleted!" })) {
    notify("User removed");
}

3. toResult<T>

Returns an object: { success: boolean; data: T | null; error: E | null }.

  • Best for: APIs that might return false or 0 as valid successful data.

🚦 Understanding RETURN_STYLES

The returnStyle determines the shape of the output when using createAsyncHandler.

| Style | Success Output | Failure Output | Use Case | | --- | --- | --- | --- | | GO_STYLE | [null, T] | [Error, null] | Classic Go-lang pattern. | | FALSE_STYLE | T | false | Data-or-False (Shielding logic). | | BOOLEAN | true | false | Pure status checks. | | ONLY_ERROR | 0 | 1 | Unix-style exit codes. |


⚙️ Advanced Control: createAsyncHandler

🌊 The Waterfall: conditionalHandlerChain

The conditionalHandlerChain follows a "First Match Wins" logic. It iterates through your array of handlers and stops as soon as one ifTrue returns true.

Key Behaviors to Remember:

  1. Stop on Match: Once a condition is met, no subsequent handlers in the chain are checked.
  2. Shielding the Default: If a handler matches, the defaultHandler is not executed. This is perfect for silencing "expected" errors (like 404s).
  3. Fallthrough: If no conditions match, the defaultHandler runs (if defined).

Example: Multi-Stage Handling

const safeFetch = createAsyncHandler({
    returnStyle: RETURN_STYLES.FALSE_STYLE,
    conditionalHandlerChain: [
        {
            ifTrue: (err) => err.code === 404,
            doIt: () => console.warn("Missing: Silently skipping logs.")
        },
        {
            ifTrue: (err) => err.code === 401,
            doIt: () => redirectToLogin()
        }
    ],
    defaultHandler: (err) => reportToSentry(err)
});

🛠️ Performance & Environment

  • Direct TS Usage: In Node.js 22.6+, run directly with --experimental-strip-types.
  • JS Distribution: For pre-bundled CJS/ESM, see wait-for-me.

All derivatives use a shared internal Go-style handler to minimize memory overhead.