promise.js 580 B

123456789101112131415
  1. // The return value is a mixin of `subprocess` and `Promise`
  2. export const mergePromise = (subprocess, promise) => {
  3. for (const [property, descriptor] of descriptors) {
  4. const value = descriptor.value.bind(promise);
  5. Reflect.defineProperty(subprocess, property, {...descriptor, value});
  6. }
  7. };
  8. // eslint-disable-next-line unicorn/prefer-top-level-await
  9. const nativePromisePrototype = (async () => {})().constructor.prototype;
  10. const descriptors = ['then', 'catch', 'finally'].map(property => [
  11. property,
  12. Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property),
  13. ]);