Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Created July 2, 2025 19:02
Show Gist options
  • Save thelinuxlich/166017bec84da9d7658fcbf2800366b4 to your computer and use it in GitHub Desktop.
Save thelinuxlich/166017bec84da9d7658fcbf2800366b4 to your computer and use it in GitHub Desktop.
lazy_promise
class LazyPromise extends Promise {
constructor(executor) {
super(executor);
if (typeof executor !== 'function') {
throw new TypeError(`executor is not a function`);
}
this._executor = executor;
}
then() {
this.promise = this.promise || new Promise(this._executor);
return this.promise.then.apply(this.promise, arguments);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment