# Code coverage report for RxJS/dist/cjs/operators/toPromise.js

## Statements: 84.21% (16 / 19) Branches: 63.64% (7 / 11) Functions: 100% (5 / 5) Lines: 84.21% (16 / 19) Ignored: none

All files » RxJS/dist/cjs/operators/ » toPromise.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33

    1
    1

    1

    1
    3

    3
    1
    1

    3

    3
    3
    3
    4

    1

    2

    1'use strict';

    exports.__esModule = true;
    exports['default'] = toPromise;

    var _utilRoot = require('../util/root');

    function toPromise(PromiseCtor) {
        var _this = this;

        if (!PromiseCtor) {
            Eif (_utilRoot.root.Rx && _utilRoot.root.Rx.config && _utilRoot.root.Rx.config.Promise) {
                PromiseCtor = _utilRoot.root.Rx.config.Promise;
            } else if (_utilRoot.root.Promise) {
                PromiseCtor = _utilRoot.root.Promise;
            }
        }
        Iif (!PromiseCtor) {
            throw new Error('no Promise impl found');
        }
        return new PromiseCtor(function (resolve, reject) {
            var value = undefined;
            _this.subscribe(function (x) {
                return value = x;
            }, function (err) {
                return reject(err);
            }, function () {
                return resolve(value);
            });
        });
    }

    module.exports = exports['default'];