Navigation

LazyPromise

LazyPromise is an async primitive that aims for maximum simplicity and draws upon ideas from RxJS, native promise and Effect. Signals have also helped shape its design by showing where the province of an async primitive should end. There are three ways to describe it.

A single-shot Observable#

Observable is beautifully simple conceptually, and has a great cancellation mechanism. LazyPromise takes care to keep that, but limits Observable to a single shot—you could say it’s a JavaScript cousin of a Single in RxJava. A single-shot Observable nicely complements Signals, and is not prone to undesirable behavior in the case of synchronous reentry.

A promise that’s lazy and cancelable, but has an otherwise familiar API#

LazyPromise API does not just resemble that of the native promise, but follows all its subtleties unless stated otherwise in the docs. This has a side benefit of making the library far easier to document and learn.

A tiny alternative to Effect#

Like Effect, and as any self-respecting lazy promise should, LazyPromise supports generator syntax, type-safe errors, and dependency injection, but does it without adding much complexity.