UNPKG

1.21 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports['default'] = waitFor;
7
8function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
9
10var _rx = require('rx');
11
12var _rx2 = _interopRequireDefault(_rx);
13
14var _debug = require('debug');
15
16var _debug2 = _interopRequireDefault(_debug);
17
18var _utils = require('./utils');
19
20var debug = (0, _debug2['default'])('thundercats:waitFor');
21var slice = Array.prototype.slice;
22
23function waitFor() {
24 return _rx2['default'].Observable.from(arguments).tapOnNext(function (observable) {
25 return (0, _utils.isObservable)(observable) ? true : new Error('waitFor only take observables but got %s', observable);
26 }).map(function (observable) {
27 return observable.publish();
28 }).tapOnNext(function (observable) {
29 return observable.connect();
30 }).toArray().tap(function () {
31 return debug('starting waitFor');
32 }).flatMap(function (arrayOfObservables) {
33 return _rx2['default'].Observable.combineLatest(arrayOfObservables, function () {
34 return slice.call(arguments);
35 });
36 }).doOnNext(function () {
37 return debug('waitFor onNext!');
38 });
39}
40
41module.exports = exports['default'];
\No newline at end of file