massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-json / node_modules / es6-promise / lib / es6-promise / then.js
1 import {
2   invokeCallback,
3   subscribe,
4   FULFILLED,
5   REJECTED,
6   noop,
7   makePromise,
8   PROMISE_ID
9 } from './-internal';
10
11 import { asap } from './asap';
12
13 export default function then(onFulfillment, onRejection) {
14   const parent = this;
15
16   const child = new this.constructor(noop);
17
18   if (child[PROMISE_ID] === undefined) {
19     makePromise(child);
20   }
21
22   const { _state } = parent;
23
24   if (_state) {
25     const callback = arguments[_state - 1];
26     asap(() => invokeCallback(_state, child, callback, parent._result));
27   } else {
28     subscribe(parent, child, onFulfillment, onRejection);
29   }
30
31   return child;
32 }