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

mika-archived/lazy-class.js

Repository files navigation

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

About

Lazy evaluation value (class) for JavaScript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published