RxJS - Comment augmenter progressivement le temps de retard sans utiliser d'intervalle?
Oct 31 2020
Je souhaite augmenter progressivement le délai pour cela:
const source = from(839283, 1123123, 63527, 4412454); // note: this is random
const spread = source.pipe(concatMap(value => of(value).pipe(delay(1000)))); // how to incrementally increase the delay where the first item emits in a second, the second item emits in three seconds, the third item emits in five seconds, and the last item emits in seven seconds.
spread.subscribe(value => console.log(value));
Je suis conscient de l'utilisation de l'intervalle pour augmenter progressivement le temps de retard comme ci-dessous. Mais j'ai aussi besoin de consommer cette sourceconst source = from(839283, 1123123, 63527, 4412454);
const source = interval(1000); // But I also need to use have this from(839283, 1123123, 63527, 4412454)
const spread = source.pipe(concatMap(value => of(value).pipe(delay(value * 200))));
spread.subscribe(value => console.log(value
Comment augmenter progressivement le temps de retard en commençant par const source = from(839283, 1123123, 63527, 4412454); ?
Réponses
3 Shorbagy Oct 31 2020 at 21:47
Vous pouvez utiliser l'indice de la valeur émise et calculer le délai en fonction de cela.
concatMap((value, index) => {
return of(value).pipe(delay((index > 2 ? 7 : index) * 1000));
})
Voici un stackblitz pour un exemple complet avec votre extrait: https://stackblitz.com/edit/rxjs-jjmlta?devtoolsheight=60