import { Subject, of } from 'rxjs';
import { delay } from 'rxjs/operators';
const queue$ = new Subject();
const clear$ = new Subject();
let queue = [];
queue$.subscribe(q => queue = q);
const addToQueue = (...args) => queue$.next(queue.concat(args));
// cycle
queue$.subscribe(() => {
if (!queue.length) {
clear$.next();
} else {
queue.shift().subscribe(res => {
console.log(new Date(), res); // logic
queue$.next(queue);
});
}
});
addToQueue(
of('itemA').pipe(delay(10)),
of('itemB').pipe(delay(1000)),
of('itemC').pipe(delay(500)),
of('itemD').pipe(delay(2000)),
);
import { Subject, of } from 'rxjs';
import { delay, concat } from 'rxjs/operators';
const itemA = of('itemA').pipe(delay(1000));
const itemB = of('itemB');
itemA.pipe(concat(itemB)).subscribe(r => {
console.log(r)
});
import { Subject, of } from 'rxjs';
import { delay, delayWhen } from 'rxjs/operators';
const triggerA = new Subject();
const itemA = of('itemA').pipe(delay(1000));
const itemB = of('itemB').pipe(delayWhen(() => triggerA));
itemA.subscribe(r => {
console.log(r);
triggerA.next()
});
itemB.subscribe(r => {
console.log(r)
});
const target = src.split(' ').map(el => el.substr(1)+el.substr(0,1)+suffix).join(' ');
Индивидуальную логику можно выполнить заранее в
.pipe(tap(res => /* here */))