Created
July 2, 2025 19:02
-
-
Save thelinuxlich/166017bec84da9d7658fcbf2800366b4 to your computer and use it in GitHub Desktop.
lazy_promise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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