RxJS dependency issue with Scheduler.async

Viewed 3226

I have the following code inside the constructor of my Angular2 component class:

var observable = Observable.create(function (observer) {
      observer.next(1);
      observer.next(2);
      observer.next(3);
      observer.complete();
    }).observeOn(Scheduler.async);

I imports include the following:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/observeOn';
import { Scheduler } from 'rxjs/Scheduler';
import 'rxjs/scheduler/async';

I tried the following import as well instead of the last import above:

import { async } from 'rxjs/scheduler/async';

I have the following error message while building my project using Angulat CLI:

Property 'async' does not exist on type 'typeof Scheduler'

What am I missing?

3 Answers

I know that this is tagged for , and , but if you landed here and are confused as to why the other answers aren't working for you, I think the location of the schedulers moved again in v6. I have a webpack development environment and I had to get the schedulers off of the bare rxjs module. You can see all of the schedulers if you inspect the module that gets imported:

import * as rxjs from "rxjs";
console.log(Object.keys(rxjs).filter(k => k.includes("Scheduler")));

Will print:

"asapScheduler"
"asyncScheduler"
"queueScheduler"
"animationFrameScheduler"
"VirtualTimeScheduler"
"Scheduler"

So if you want async Scheduler you can do:

import {asyncScheduler} from "rxjs";
Related