Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Latest commit

 

History

History
34 lines (24 loc) · 993 Bytes

README.md

File metadata and controls

34 lines (24 loc) · 993 Bytes

Lazy Class

GitHub CircleCI npm (scoped)

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