2.0.2 • Published 3 years ago

lazy_global v2.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

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.
    }
}
2.0.2

3 years ago

2.0.1

3 years ago

3.0.0

3 years ago

2.0.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago