0

I have a class which accepts a callback on construction so that it can send data back to its parent.

class Chain {
  _callback: (data: ChainData) => void;

  constructor(callback: (data: ChainData) => void) {
    this._callback = callback;
    setInterval(this._refresh, 13 * 1000);
  }

  private async _refresh() {

    this._callback({
      height: 1,
      difficulty: 2,
      hashrate: 3,
      blocktime: 4
    });
  }
}

What I find interesting is that this works perfectly but I get this error every time its called. Again, it is functionally 100% working.

(node:26146) UnhandledPromiseRejectionWarning: TypeError: this._callback is not a function
    at Timeout.<anonymous> (/Users/lukepighetti/code/typescript/bot/lib/services/chain.ts:17:10)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/lukepighetti/code/typescript/bot/lib/services/chain.ts:4:58)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)

What am I doing wrong and how do I get rid of this seemingly pointless error?

Luke Pighetti
  • 4,541
  • 7
  • 32
  • 57

0 Answers0