I tried to implement custom promise implementation using plain vanilla JavaScript. But its not working for async then function. How do I make async chaining in my code?
Here is my code:
var noop = () => { };
function Promise(callback) {
  callback = callback || noop;
  var thenCallbacks = [];
  this.promisedValue = null;
  this.then = function (callback) {
    callback = callback || noop;
    thenCallbacks.push(callback);
    //this.promisedValue = callback(this.promisedValue) || this.promisedValue;
    return this;
  }
  this.done = function () {
    if (!thenCallbacks.length) {
      debugger;
      return this.promisedValue;
    } else {
      for (var i = 0; i < thenCallbacks.length; i++) {
        this.promisedValue = thenCallbacks[i].call(this, this.promisedValue);
      }
    }
    debugger;
    return this.promisedValue;
  }
  var res = (d) => {
    this.promisedValue = d;
  }
  var rej = (d) => {
    this.promisedValue = d;
  }
  callback.call(this, res, rej);
};
var p = new Promise((res, rej) => {
  res(100);
}).then((d) => {
  console.log('Then 1 called!! ', d);
  return 100233;
}).done();