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

@efesto-cloud/result-async

v0.1.1

Published

Async Result type for efesto-cloud — companion to @efesto-cloud/result

Readme

@efesto-cloud/result-async

Asynchronous Result<T, E> for representing the outcome of operations that can succeed or fail without throwing. Companion to @efesto-cloud/result.

Installation

pnpm add @efesto-cloud/result-async

Quick Start

import ResultAsync, { okAsync, errAsync } from "@efesto-cloud/result-async";

declare function loadUser(id: string): Promise<User>; // may reject

function safeLoadUser(id: string) {
    return ResultAsync.fromPromise(loadUser(id), (e) => new DbError(e));
}

const r = await safeLoadUser("42");
if (r.isFailure()) {
    console.error(r.error);
} else {
    console.log(r.data.name);
}

Core Rules

  • Wrap a rejecting Promise with ResultAsync.fromPromise(p, mapErr).
  • Wrap a non-rejecting Promise with ResultAsync.fromSafePromise(p).
  • Create from a value with okAsync(value) / errAsync(error).
  • await a ResultAsync<T, E> to get a Result<T, E>.
  • Use unwrapOrThrow() only when crashing fast is the intended behavior.

API

Constructors

okAsync(value);                                       // ResultAsync<T, never>
errAsync(error);                                      // ResultAsync<never, E>

ResultAsync.fromPromise(p, (e) => mapped);            // wrap a rejecting promise
ResultAsync.fromSafePromise(p);                       // wrap a non-rejecting promise
ResultAsync.fromThrowable(asyncFn, (e) => mapped);    // wrap an async function

Instance methods

| Method | Purpose | | --- | --- | | then(...) | Implements PromiseLike, so await ra returns Result<T, E>. | | map(fn) | Transform data; error passes through. fn may be async. | | mapError(fn) | Transform error; data passes through. fn may be async. | | flatMap(fn) / andThen(fn) | Chain another Result / ResultAsync / Promise<Result>. | | orElse(fn) | Recover from a failure by returning a new Result/ResultAsync. | | match(onOk, onErr) | Collapse to a single value. Returns a Promise. | | tap(fn) | Side-effect on success; passes the value through. | | tapError(fn) | Side-effect on failure; passes the value through. | | unwrapOr(fallback) | Returns Promise<T \| U> — data or fallback. | | unwrapOrThrow() | Returns Promise<T> or throws the error. |

Patterns

Chain two async calls

function loadProfile(id: string) {
    return ResultAsync.fromPromise(fetchUser(id), toDbError)
        .andThen((user) =>
            ResultAsync.fromPromise(fetchPosts(user.id), toDbError).map(
                (posts) => ({ user, posts }),
            ),
        );
}

Bridge from a sync Result

import { ok } from "@efesto-cloud/result";

function start() {
    return okAsync(1).andThen((n) => ok(n + 1)); // ResultAsync<number, never>
}

Recover

const safe = riskyAsync().orElse((e) =>
    e.kind === "transient" ? okAsync(0) : errAsync(e),
);