I know that the function delay()
allows to delay all the events but I only need it to delay the first 2, for example try this:
https://stackblitz.com/edit/k4xb43?file=index.ts
const clicks = fromEvent(document, "click");
const delayedClicks = clicks.pipe(
take(2),
delay(500)
); // each click emitted after 1 second
delayedClicks.subscribe(x => console.log(x));
it delays the execution but then I block all the events, how could I delay it only in the first 2 executions?
Now that I've taken the time to answer, I'll show you an example in case you haven't solved it yet or in case someone else comes across something similar. What you could do is use the delayWhen operator together with a counter or, depending on what you are doing, use a variable or function and based on the result, execute the delay, for example:
The delayWhen operator delays the emission for a certain period of time, and with the tap() operator you intercept each emission of the observable and execute a function, it can be used as a debugger in the observables to check errors or perform some action or side effect. Cheers!! :)