"use strict";
var RxNode = require('rx-node');
var Rx = require('rx');
var types = {
    observable: {
        predicate: function (input) {
            return Rx.Observable.isObservable(input);
        },
        handle: handleObs
    },
    promise: {
        predicate: function (input) {
            return typeof input.then === 'function';
        },
        handle: handlePromise
    },
    nodeStream: {
        predicate: function (input) {
            return typeof input.on === 'function';
        },
        handle: handleNodeStream
    }
};
function handleReturnType(output, cb) {
    var match = Object.keys(types).filter(function (x) {
        return types[x].predicate.call(null, output);
    })[0];
    if (match && typeof types[match].handle === 'function') {
        return types[match].handle.apply(null, [output, cb]);
    }
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = handleReturnType;
;
function handleNodeStream(output, done) {
    return RxNode.fromStream(output, 'end')
        .subscribe(function (val) {
    }, function (err) {
        done(err);
    }, function () {
        done();
    });
}
function handlePromise(output, done) {
    return Rx.Observable
        .fromPromise(output)
        .subscribe(function (val) {
    }, function (err) {
        done(err);
    }, function () {
        done();
    });
}
function handleObs(output, done) {
    return output
        .subscribe(function (val) {
    }, function (e) {
        done(e);
    }, function () {
        done();
    });
}
//# sourceMappingURL=task.return.values.js.map