Skip to content Skip to sidebar Skip to footer

Tracking/Logging Promises

I am trying to find a solution for tracking Promises. The project that I am working on has some dangling async tasks that are not awaited/yielded. I am trying to find such cases, a

Solution 1:

You can monkey patch the promise constructor like this:

const global = window; // (in browser...)
const OldPromise = global.Promise; 
global.Promise = class Promise extends OldPromise {
    constructor(executor) {
    // do whatever you want here, but must call super()
    console.log('hello, promise');

    super(executor); // call native Promise constructor
  }
};

Promise.resolve();

Source: Monkey-patch Promise constructor


Post a Comment for "Tracking/Logging Promises"