What do you think of LazyPromise as a lightweight alternative to Effect?
LazyPromise is a lightweight alternative to Effect, offering a promise-like API while taking care to maintain key features from Observable. It emits synchronously instead of in a microtask, supports typed errors, and has a dependency injection system.
One key difference between LazyPromise and native Promise is the cancellation mechanism. While native Promise is eager, LazyPromise supports cancellation via AbortController API. Additionally, LazyPromise avoids the "Zalgo" guarantee that native Promise provides, ensuring that microtasks are not mandatory.
Like Observable, LazyPromise runs its constructor callback each time someone subscribes, unlike native Promise which executes only once. LazyPromise also shares similarities with a single-shot Observable, which complements Signals without falling into the "Diamond Problem."
In terms of API, LazyPromise mirrors native Promise, including features like cancelling upstream LazyPromise derived from operators, supporting AbortController API, and providing methods to convert between LazyPromise and Promise. LazyPromise also introduces the concept of boxed errors, allowing for type checking of errors without the need for an extra channel like native Promise.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.