当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.timer方法代码示例

本文整理汇总了TypeScript中rxjs.Observable.timer方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.timer方法的具体用法?TypeScript Observable.timer怎么用?TypeScript Observable.timer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rxjs.Observable的用法示例。


在下文中一共展示了Observable.timer方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: callback

 return source.retryWhen(errors => {
     return Observable
         .zip(Observable.range(1, backoffRetries), errors, (i, e) => [i, e])
         .do(data => callback(data[1]))
         .flatMap(data => Observable.timer(data[0] * data[0] * backoffInterval))
         .concat(Observable
             .timer(pollingInterval, pollingInterval)
             .zip(errors, (timer, error) => error)
             .do(error => callback(error)));
 });
开发者ID:tierratelematics,项目名称:prettygoat,代码行数:10,代码来源:TypesUtil.ts

示例2: checkPanel

        function checkPanel(): any {
            const panels = atom.workspace.getModalPanels();
            if (panels.length) {
                const panelItem: GenericSelectListView = panels[0].item;
                expect(panelItem._items.length).to.be.eql(2);

                panelItem.onConfirm(panelItem._items[0].name);

                return p;
            } else {
                return Observable.timer(100).toPromise()
                    .then(() => checkPanel());
            }
        }
开发者ID:Member1221,项目名称:omnisharp-atom,代码行数:14,代码来源:solution-manager-spec.ts

示例3: factory

function createObservable<T>(factory: () => Promise<T>): Observable<T> {
  const topic: Promise<T> = factory();

  if (topic instanceof Promise) {
    const lazyRec: () => Observable<T> = () => {
      return Observable.fromPromise(factory()).concat(
          Observable.timer(60 * 60 * 1000).flatMap(() => lazyRec()));
    };

    return Observable.fromPromise(topic).concat(
        Observable.timer(60 * 60 * 1000).flatMap(() => lazyRec()));
  } else {
    return Observable.fromPromise(topic);
  }
}
开发者ID:blmarket,项目名称:simple-amd,代码行数:15,代码来源:factory-loader.ts

示例4: Promise

    return new Promise(async resolve => {
      await Observable.timer(1000).toPromise();
      let a = document.createElement('a');
      let blob = this.newBlob(ew, 'text/plain;charset=utf-8');
      let url = window.URL.createObjectURL(blob);

      document.body.appendChild(a);

      a.href = url;
      a.download = fileName;
      a.click();
      window.URL.revokeObjectURL(url);

      return resolve();
    });
开发者ID:bitpay,项目名称:copay,代码行数:15,代码来源:download.ts

示例5: constructor

 constructor(private http: Http, private randomMessage: RandomMessage) {
     this.messages$ = new Subject<Message>();
     Observable.timer(0, 3000)
         // .take(5)
         .delayWhen(_ => Observable.interval(Math.random() * 10000))
         .switchMap(_ => {
             return this.http.get('https://randomuser.me/api/')
         })
         .map(resp => resp.json())
         .subscribe((data: any) => {
             const user = data.results[0];
             this.messages$.next({
                 id: Date.now(),
                 name: namenize(user.name.first),
                 image: user.picture.thumbnail,
                 message: this.randomMessage.get()
             });
         }, error => {
             console.error(error);
         });
 }
开发者ID:laco0416,项目名称:ng2-demo-chat,代码行数:21,代码来源:chat.service.ts

示例6: watchForAutoLogin

  watchForAutoLogin(): Observable<ILoginActionPayload> {
    const isAuto = ( loginState: ILoginState ): boolean => {
      if (loginState)
        return loginState.userId === null;
      return false;
    };

    let meteorUser = Meteor.user();
    let lastLoginState = null;
    ReduxPackageCombiner
      .select(LOGIN_PACKAGE_NAME)
      .subscribe((loginState: ILoginState) => {
        lastLoginState = loginState;
      });
    if (meteorUser) {
      return Observable.of(LoginActions.loginSuccessFactory(
        this.userFromMeteorUser(meteorUser),
        meteorUser._id,
        isAuto(lastLoginState)
      ));
    }

    let subject = new Subject();
    let timer = Observable.timer(500, 1000);
    let subscription = timer.subscribe(() => {
      let meteorUser = Meteor.user();
      if (meteorUser) {
        subject.next( LoginActions.loginSuccessFactory(
          this.userFromMeteorUser(meteorUser),
          meteorUser._id,
          isAuto(lastLoginState)
        ));
        subject.complete();
        subscription.unsubscribe();
      }
    });
    return subject;
  };
开发者ID:kokokenada,项目名称:for-real-cards,代码行数:38,代码来源:login-service-meteor.ts

示例7: run

export function run() {
    const stream = Observable.timer(1000,1000);
    stream.subscribe(value => console.log(value));  
}
开发者ID:cyrilpanicker,项目名称:rxjs-demo,代码行数:4,代码来源:timer.ts

示例8:

 .debounce((x) => {
   return Rx.Observable.timer(500);
 })
开发者ID:pdecembre,项目名称:batarangle,代码行数:3,代码来源:frontend.ts

示例9: lazyRec

 const lazyRec: () => Observable<T> = () => {
   return Observable.fromPromise(factory()).concat(
       Observable.timer(60 * 60 * 1000).flatMap(() => lazyRec()));
 };
开发者ID:blmarket,项目名称:simple-amd,代码行数:4,代码来源:factory-loader.ts

示例10: createScheduler

  public static createScheduler(pollSchedule = SETTINGS.pollSchedule): IScheduler {
    let scheduler = new Subject();

    let lastRunTimestamp = new Date().getTime();
    let pendingRun: IPromise<void> = null;
    let suspended = false;

    // When creating the timer, use last run as the dueTime (first arg); zero can lead to concurrency issues
    // where the scheduler will fire shortly after being subscribed to, resulting in surprising immediate refreshes
    let source = Observable.timer(pollSchedule, pollSchedule);

    const run = (): void => {
      if (suspended) {
        return;
      }
      $timeout.cancel(pendingRun);
      lastRunTimestamp = new Date().getTime();
      scheduler.next(true);
      pendingRun = null;
    };

    source.subscribe(run);

    const suspendScheduler = (): void => {
      $log.debug('auto refresh suspended');
      suspended = true;
    };

    const scheduleNextRun = (delay: number) => {
      // do not schedule another run if a run is pending
      suspended = false;
      pendingRun = pendingRun || $timeout(run, delay);
    };

    const resumeScheduler = (): void => {
      suspended = false;
      const now = new Date().getTime();
      $log.debug('auto refresh resumed');
      if (now - lastRunTimestamp > pollSchedule) {
        run();
      } else {
        scheduleNextRun(pollSchedule - (now - lastRunTimestamp));
      }
    };

    const watchDocumentVisibility = (): void => {
      $log.debug('document visibilityState changed to: ', document.visibilityState);
      if (document.visibilityState === 'visible') {
        resumeScheduler();
      } else {
        suspendScheduler();
      }
    };

    const scheduleImmediate = (): void => {
      run();
      suspended = true;
      scheduleNextRun(pollSchedule);
    };

    document.addEventListener('visibilitychange', watchDocumentVisibility);
    $window.addEventListener('offline', suspendScheduler);
    $window.addEventListener('online', resumeScheduler);
    scheduler.next(true);

    return {
      subscribe: scheduler.subscribe.bind(scheduler),
      scheduleImmediate,
      unsubscribe: () => {
        suspended = true;
        if (scheduler) {
          scheduler.next(false);
          scheduler.unsubscribe();
        }
        scheduler = null;
        source = null;
        $timeout.cancel(pendingRun);
        document.removeEventListener('visibilitychange', watchDocumentVisibility);
        $window.removeEventListener('offline', suspendScheduler);
        $window.removeEventListener('online', resumeScheduler);
      },
    };
  }
开发者ID:emjburns,项目名称:deck,代码行数:83,代码来源:SchedulerFactory.ts


注:本文中的rxjs.Observable.timer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。