hugoWebsite/node_modules/rxjs/dist/esm/internal/observable/race.js

25 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-10-29 00:20:35 +02:00
import { Observable } from '../Observable';
import { innerFrom } from './innerFrom';
import { argsOrArgArray } from '../util/argsOrArgArray';
import { createOperatorSubscriber } from '../operators/OperatorSubscriber';
export function race(...sources) {
sources = argsOrArgArray(sources);
return sources.length === 1 ? innerFrom(sources[0]) : new Observable(raceInit(sources));
}
export function raceInit(sources) {
return (subscriber) => {
let subscriptions = [];
for (let i = 0; subscriptions && !subscriber.closed && i < sources.length; i++) {
subscriptions.push(innerFrom(sources[i]).subscribe(createOperatorSubscriber(subscriber, (value) => {
if (subscriptions) {
for (let s = 0; s < subscriptions.length; s++) {
s !== i && subscriptions[s].unsubscribe();
}
subscriptions = null;
}
subscriber.next(value);
})));
}
};
}
//# sourceMappingURL=race.js.map