File: merge-promise.js

package info (click to toggle)
node-multipipe 4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 328 kB
  • sloc: javascript: 284; makefile: 4
file content (18 lines) | stat: -rw-r--r-- 565 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'use strict'

// Adapted from
// https://github.com/sindresorhus/execa/blob/120230cade59099214905ac2a9136e406c0b6f3a/lib/promise.js

const descriptors = ['then', 'catch', 'finally'].map(property => [
  property,
  Reflect.getOwnPropertyDescriptor(Promise.prototype, property)
])

module.exports = (stream, createPromise) => {
  for (const [property, descriptor] of descriptors) {
    const value = (...args) =>
      Reflect.apply(descriptor.value, createPromise(), args)
    Reflect.defineProperty(stream, property, { ...descriptor, value })
  }
  return stream
}