lazy_global
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

Lazy Global

Some utilities for creating lazily evaluated objects

Example

import { lazy } from "lazy_global";

const LAZY_OBJECT = lazy(() => "Some expensive to compute value");

function doSomething() {
    const lazyValue = LAZY_OBJECT.value();
}
import { lazyPromise } from "lazy_global";

const LAZY_OBJECT = lazyPromise(async () => {
    if (somethingThatCanFail()) {
        return "Some expensive to compute value";
    }

    return Promise.reject("Failure value");
});

function doSomething() {
    try {
        const lazyValue = LAZY_OBJECT.value();
    } catch (error) {
        console.assert(error === "Failure value");
        // Handle the case where the value is not available.
    }
}

Dependents (0)

Package Sidebar

Install

npm i lazy_global

Weekly Downloads

2

Version

2.0.2

License

MIT

Unpacked Size

1.73 kB

Total Files

2

Last publish

Collaborators

  • rope_