@mikazuki/lazy-class
v0.0.2
Published
Lazy evaluation value (class) for JavaScript.
Downloads
2
Readme
Lazy Class
Lazy evaluation value (class) for JavaScript.
Install
yarn add @mikazuki/lazy-class
How to use
import { AsyncLazy, Lazy } from "@mikazuki/lazy-class";
// sync
const lazy = new Lazy<string>(() => "Hello, World");
lazy.isValueInitialized; // => false
lazy.value; // => "Hello, World"
lazy.isValueInitialized; // => true
// async
const fetch = async () => new Promise(resolve => resolve("Hello, World"));
const asyncLazy = new AsyncLazy<string>(async () => await fetch());
asyncLazy.isValueInitialized; // => false
await asyncLazy.value; // => "Hello, World"
asyncLazy.isValueInitialized; // => true