RxJS dependency issue with Scheduler.async

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

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

I import the following items:

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

I tried the following import, not the last import above:

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

I get the following error message when building my project using the Adulit CLI:

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

What am I missing?

+4
source share
2 answers

yes, this is correct because:

import { Scheduler } from 'rxjs/Scheduler';

this means that you have imported this class: https://github.com/ReactiveX/rxjs/blob/5.4.0/src/Scheduler.ts#L8-L63

and

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

https://github.com/ReactiveX/rxjs/blob/5.4.0/src/scheduler/async.ts#L47

, , Scheduler async, , Rx.Scheduler.async , :

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);
+6

, .

:

import { Scheduler } from 'rxjs/Scheduler';

Scheduler, , , . , , :

import { Scheduler } from 'rxjs/Scheduler';

class MyClass {
    sched: Scheduler;
}

async, AsyncScheduler. , AsyncScheduler.

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

, , , :

async.now();

rxjs/scheduler/async Scheduler, rxjs, Rx.ts

import { Scheduler } from 'rxjs';

...

Scheduler.async.now();

, : https://github.com/ReactiveX/rxjs/blob/master/src/Rx.ts#L193-L198

, async 'rxjs/scheduler/async' Scheduler.async 'rxjs'. async from Rx.ts 'rxjs/scheduler/async', rxjs, , Rx.ts. , , , , , .

'rxjs/scheduler/async', 'rxjs':

import { async } from 'rxjs/scheduler/async'
+5

Source: https://habr.com/ru/post/1678454/


All Articles