CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
thenify.js61 linesDownload Raw Back to lib
1'use strict'2 3const { debug } = require('./debug')4const { kThenifyDoNotWrap } = require('./symbols')5 6/**7 * @callback PromiseConstructorLikeResolve8 * @param {any} value9 * @returns {void}10 */11 12/**13 * @callback PromiseConstructorLikeReject14 * @param {reason} error15 * @returns {void}16 */17 18/**19 * @callback PromiseConstructorLike20 * @param {PromiseConstructorLikeResolve} resolve21 * @param {PromiseConstructorLikeReject} reject22 * @returns {void}23 */24 25/**26 * @returns {PromiseConstructorLike}27 */28function thenify () {29  // If the instance is ready, then there is30  // nothing to await. This is true during31  // await server.ready() as ready() resolves32  // with the server, end we will end up here33  // because of automatic promise chaining.34  if (this.booted) {35    debug('thenify returning undefined because we are already booted')36    return37  }38 39  // Calling resolve(this._server) would fetch the then40  // property on the server, which will lead it here.41  // If we do not break the recursion, we will loop42  // forever.43  if (this[kThenifyDoNotWrap]) {44    this[kThenifyDoNotWrap] = false45    return46  }47 48  debug('thenify')49  return (resolve, reject) => {50    const p = this._loadRegistered()51    return p.then(() => {52      this[kThenifyDoNotWrap] = true53      return resolve(this._server)54    }, reject)55  }56}57 58module.exports = {59  thenify60}61