Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
Espera en observables anidados

Soy nuevo en Observables; Tengo que convertir un bucle for anidado con Observables y, cuando se cumple una condición, esperar una cierta cantidad de tiempo.
Pude convertir el bucle for con Observables, pero no alcancé a lograr la "pausa" del flujo de 5 segundos después de que el valor de la variable globalCounter se establece en 5.
¿Cómo hacerlo? Gracias.

 import { map, Observable, Subject } from "rxjs"; const array1 = ["Alfa", "Beta", "Gamma"]; const array2 = ["Laura", "Valentina", "Cristina"]; const array3 = ["Red", "Green", "Blue"]; const mySubject = new Subject<number>(); let globalCounter = 0; const myObservable1$ = new Observable<string>((observer1) => { array1.map((u) => { observer1.next(u); }); }); const pipeline1 = myObservable1$ .pipe( map(async (value1) => { const return2 = await fObservable2(value1); return2.subscribe({}); }) ) .subscribe(); async function fObservable2(value1: string) { return new Observable<string>((observer2) => { array2.map(async (d) => { const valueToPassTofObservable3 = value1 + " --- " + d; const return3 = await fObservable3(valueToPassTofObservable3); return3.subscribe({ next: async (value3) => { console.log( `OBSERVABLE2 - value3: ${value3} - globalCounter: ${globalCounter}` ); }, }); }); }); } async function fObservable3(value2: string) { let toBeReturn3; if (globalCounter === 5) { await sleep(); } return new Observable<string>((observer3) => { array3.forEach((t) => { toBeReturn3 = t + " --- " + value2; observer3.next(toBeReturn3); mySubject.next(globalCounter++); }); }); } function sleep() { return new Promise((resolve) => { setInterval(() => { globalCounter = 0; resolve(true); }, 5000); }); }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!