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

231
Views
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 answers
Answer question

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 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!