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.

Revisions

  1. thelinuxlich created this gist Jul 2, 2025.
    13 changes: 13 additions & 0 deletions lazy_promise.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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);
    }
    }