Into a rxjs-Stream i want to conditionaly insert data, a delay and then the original event.
from(Array(10).keys())
.pipe(
map(i => ({ data: i })),
concatMap(e => {
if (e.data === 3) {
return of(e)
.pipe(
delay(500),
);
}
return of(e);
}),
)
.subscribe(i => console.log(i));
This creates a delay before { data: 3 }
.
But i want to emit { data: 'a' }
, delay, { data: 3 }
.
2
Answers
You can achieve this by inserting a conditional delay before emitting the original event. Here’s how you can modify the code:
This will emit { data: ‘a’ }, followed by a delay, and then emit { data: 3 }.
You can use
merge
method to achieve what you want :Stackblitz