當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。