示例#1
0
const waitForServerReachable = () => {
    return interval(1000).pipe(
        mergeMap(async () => {
            try {
                const statusCode = await fetchResponse();
                if (statusCode === 200) return true;
            } catch (err) {}
            return false;
        }),
        filter(ok => !!ok)
    );
};
示例#2
0
  subscribe() {
    const mesos$ = container.get(MesosStreamType);
    const masterRequest$ = container.get(MesosMasterRequestType).pipe(
      tap(response => {
        const master = mesosStreamParsers.getMaster(
          this.getMaster(),
          JSON.parse(response)
        );
        CompositeState.addState(master);
        this.setMaster(master);
      })
    );

    const parsers = pipe(...Object.values(mesosStreamParsers));
    const data$ = mesos$.pipe(
      merge(masterRequest$),
      distinctUntilChanged(),
      map(message => parsers(this.getLastMesosState(), JSON.parse(message))),
      tap(state => this.setState(state), console.error)
    );

    const wait$ = masterRequest$.pipe(zip(mesos$.pipe(take(1))));
    const eventTrigger$ = data$.pipe(
      merge(
        // A lot of DCOS UI rely on the MesosStateStore emitting
        // MESOS_STATE_CHANGE events. After the switch to the stream, we lost this
        // event. To avoid a deeper refactor, we introduced this fake emitter.
        //
        // TODO: https://jira.mesosphere.com/browse/DCOS-18277
        interval(Config.getRefreshRate())
      )
    );

    // Since we introduced the fake event above, we have to guarantee certain
    // refresh limits to the UI. They are:
    //
    // MOST once every (Config.getRefreshRate() * 0.5) ms. due to sampleTime.
    // LEAST once every tick of Config.getRefreshRate() ms in
    // Observable.interval
    //
    // TODO: https://jira.mesosphere.com/browse/DCOS-18277
    this.stream = wait$
      .pipe(
        concat(eventTrigger$),
        sampleTime(Config.getRefreshRate() * 0.5),
        retryWhen(linearBackoff(RETRY_DELAY, -1, MAX_RETRY_DELAY))
      )
      .subscribe(
        () => Promise.resolve().then(this.onStreamData),
        this.onStreamError
      );
  }
    _whenBaseLayerIsLoaded() {

      if (!this._baseLayerConfigured()) {
        return true;
      }

      const maxTimeForBaseLayer = 10000;
      const interval$ = Rx.interval(10).pipe(filter(() => !this._baseLayerDirty));
      const timer$ = Rx.timer(maxTimeForBaseLayer);

      return Rx.race(interval$, timer$).pipe(first()).toPromise();

    }
示例#4
0
文件: Deamon.js 项目: tsuyuno/imanani
import { interval, Subject } from 'rxjs';
import {filter} from "rxjs/operators";
import bucket from "./Bucket";
import {Poster} from "./Poster";
import store from "store";
import Api from '../api/Api';
import { CommunityBuilder, ProgramBuilder } from './ManageableBuilder';

const AUTOMATIC_VISITING_KEY = "autoEnterProgramList";

interval(1000 * 30).subscribe(
  _ => {
    const communities = bucket.communitiesShouldPoll();
    communities.forEach((community, i) => {
      const delay = i * 3000;
      setTimeout(() => {
        Api.isOpen(community.id).then(result => {
          if (result.isOpen) {
            // Build Manageable objects.
            const communityBuilder = new CommunityBuilder()
              .id(community.id);
            const programBuilder = new ProgramBuilder()
              .id(result.nextLiveId)
              .title(result.title)
              .isVisiting(false)
              .shouldOpenAutomatically(true);
            // Assign.
            bucket.touchBoth(communityBuilder, programBuilder);
          }
        })
      }, delay);
示例#5
0
 IntervalObservable.create = function (period, scheduler) {
     if (period === void 0) { period = 0; }
     if (scheduler === void 0) { scheduler = asyncScheduler; }
     return interval(period, scheduler);
 };
示例#6
0
    if (timerSel.status(state) === 'started') {
      // already started just silently reject
      return reject();
    }
    if (timerSel.value(state) > 0) {
      allow(action);
    } else {
      reject(timerStartError(new Error('Can\'t start, already zero. Reset first')));
    }
  },

  // by omitting dispatch and done, process will use the return
  // to determine what to dispatch. In this case we returned
  // an observable so it will dispatch any values that were emitted
  process(depObj) {
    return interval(1000).pipe(
      map(() => timerDecrement()) // send timerDecrement actions
    );
  }
});

const timerDecrementLogic = createLogic({
  type: TIMER_DECREMENT,

  validate({ getState, action }, allow, reject) {
    const state = getState();
    if (timerSel.value(state) > 0) {
      allow(action);
    } else { // shouldn't get here, but if does end
      reject(timerEnd());
    }
 static create(period = 0, scheduler = asyncScheduler) {
     return interval(period, scheduler);
 }