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?
yes, this is correct, because:
import { Scheduler } from 'rxjs/Scheduler';
this mean, you imported this class: https://github.com/ReactiveX/rxjs/blob/5.4.0/src/Scheduler.ts#L8-L63
and
import { async } from 'rxjs/scheduler/async';
is https://github.com/ReactiveX/rxjs/blob/5.4.0/src/scheduler/async.ts#L47
So you can see, Scheduler
does not have async
property, I guess you wanna convert this thing Rx.Scheduler.async
source code here, you could try this solution:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/observeOn';
import { async } from 'rxjs/scheduler/async';
var observable = Observable.create(function (observer) {
observer.next(1);
observer.next(2);
observer.next(3);
observer.complete();
}).observeOn(async);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With