Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

241
Vistas
observeOn(queueScheduler) make no difference with null scheduler

I'm new to RxJS, and is learning the Schedulers topic, what confuse me is the difference between queueScheduler and null scheduler.

I have read the RxJS docs and some blogs about this topic.

I thought I've got the idea about the difference, but the following code just break all my 'understandings'.

combineLatest([
  // scheduled([1, 2], asyncScheduler), // [1, 10], [2, 10]
  // scheduled([1, 2], queueScheduler),  // just [2, 10]
  from([1, 2]), // just [2, 10]
  from([10]),
]).subscribe(console.log);

According to this answer, using the queue scheduler turns the streams somehow 'breadth first', so I was expecting [1, 10], [2, 10] when using the queueScheduler just the same as asyncScheduler in this case.

Any one can explain why this happen, or am I doing something wrong?

Thanks!

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

To be honest I'm not very confident how the queueScheduler is implemented and what is its typical real world use-case.

One example where queueScheduler and asyncScheduler differ is when expecting synchronous behavior while making recursive emissions that trigger another emission. Without any scheduler this would create an infinite loop but with queueScheduler I can still have synchronous code.

import { observeOn, asyncScheduler, queueScheduler, Subject } from 'rxjs';

const subject = new Subject<number>();

console.log('before');
const sub = subject
  .pipe(
    observeOn(asyncScheduler),
    // observeOn(queueScheduler),
  )
  .subscribe(v => {
    console.log(v);
    subject.next(v + 1);

    if (v > 10) {
      sub.unsubscribe();
    }
  });

subject.next(1);
console.log('after');

Live demo: https://stackblitz.com/edit/rxjs-945r4b?devtoolsheight=60&file=index.ts

If you uncomment observeOn(queueScheduler) you'll get the same result but the chain is invoked asynchronously.

Regarding using null as a scheudler I'm not sure what bahavior is expected. AFAIK a lot has changed since RxJS 5 and how it works with schedulers by default. The answer you mention was posted in 2018 so I would expect that what's written there might be obsolete.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda