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

281
Views
Emitir valores de Observable.from en un intervalo

Tengo una serie de elementos que quiero emitir desde un Observable en un intervalo.

Estoy usando la biblioteca rxjs incluida en Angular 2.

Esta es mi solución actual, pero siento que hay un método reactivo que no encuentro. Esta solución también continúa produciendo valores después de que se agota la matriz, pero realmente debería completarse. ¿Hay alguna forma de conducir Observable.from con Observable.interval ?:

 var array = [1,2,3]; var source = Rx.Observable .interval(500 /* ms */) .map(function() { return array.pop(); }); var subscription = source.subscribe( function (x) { console.log('Next:', x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); });

Producción:

 "Next:" 3 "Next:" 2 "Next:" 1 "Next:" undefined
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Para algo tan simple como eso, lo que ha hecho está bien, excepto que prefiero usar el índice dado desde el interval para leer la matriz en ese índice dado en lugar de usar pop que modifica la matriz original (mezclado con programación reactiva es una especie de extraño, ¿no es así =) !)

Te hice otra propuesta para que puedas descubrir otros operadores tal vez:

 const { Observable } = Rx const myArray = [1, 2, 3] const interval$ = Observable.interval(500) Observable .from(myArray) .zip(interval$) .do(([x]) => console.log(x)) .subscribe( () => {}, () => {}, () => console.log('Stream ended !') )
 <script src="https://unpkg.com/rxjs@5.1.1/bundles/Rx.min.js"></script>

about 4 years ago · Santiago Trujillo Report
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!