@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
47 lines • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
// (C) 2007-2020 GoodData Corporation
var identity = require("lodash/identity");
var rxjs_1 = require("rxjs");
exports.Subscription = rxjs_1.Subscription;
var operators_1 = require("rxjs/operators");
/**
* Creates infinite stream
* Usage:
* const subject = createSubject(
* (result) => console.log('Success:', result),
* (error) => console.error('Error:', error)
* );
* subject.next(promise1);
* subject.next(promise2);
*
* subject.unsubscribe();
*
* @param successHandler
* @param errorHandler
*/
function createSubject(successHandler, errorHandler) {
var subject = new rxjs_1.Subject();
var subscription = subject
.pipe(
// This ensures we get last added promise
operators_1.switchMap(identity),
// Streams are closed on error by default so we need this workaround
operators_1.catchError(function (error, caught) {
errorHandler(error); // handle error
return caught; // stream continue
}))
.subscribe(successHandler);
var wrapper = {
next: function (promise) {
subject.next(promise);
},
unsubscribe: function () {
subscription.unsubscribe();
subject.unsubscribe();
},
};
return wrapper;
}
exports.createSubject = createSubject;
//# sourceMappingURL=async.js.map