Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda