rx.Observable.timer()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中rx.Observable.timer()方法的一些代码示例,展示了Observable.timer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.timer()方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:timer

Observable.timer介绍

[英]Returns an Observable that emits a 0L after the initialDelay and ever increasing numbers after each period of time thereafter.

Backpressure Support: This operator does not support backpressure as it uses time. If the downstream needs a slower rate it should slow the timer or use something like #onBackpressureDrop. Scheduler: timer operates by default on the computation Scheduler.
[中]返回一个可观测值,该值在初始延迟后发出0L,此后的每一段时间后都会不断增加。
背压支持:该操作员不支持背压,因为它使用时间。如果下游需要较慢的速度,则应减慢计时器或使用#onBackpressureDrop之类的方法。调度程序:默认情况下,计时器在计算调度程序上运行。

代码示例

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
  public Observable<Long> call(String s) {
    playVideo(s);
    return Observable.timer(2000, TimeUnit.MILLISECONDS);
  }
})

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  //
  Scheduler scheduler = io.vertx.rxjava.core.RxHelper.scheduler(vertx);

  // Create a periodic event stream using Vertx scheduler
  Observable<Long> o = Observable.
    timer(0, 1000, TimeUnit.MILLISECONDS, scheduler);

  o.subscribe(item -> {
   System.out.println("Got item " + item);
  });
 }
}

代码示例来源:origin: ReactiveX/RxNetty

public PoolConfig() {
  maxIdleTimeMillis = DEFAULT_MAX_IDLE_TIME_MILLIS;
  idleConnCleanupTicker = Observable.timer(maxIdleTimeMillis, TimeUnit.MILLISECONDS);
  idleConnectionsHolder = new FIFOIdleConnectionsHolder<>();
  limitDeterminationStrategy = UnboundedPoolLimitDeterminationStrategy.INSTANCE;
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

/**
 * 图片开始轮播
 */
private void startScroll() {
 compositeSubscription = new CompositeSubscription();
 isStopScroll = false;
 Subscription subscription = Observable.timer(delayTime, TimeUnit.SECONDS)
   .subscribeOn(Schedulers.io())
   .observeOn(AndroidSchedulers.mainThread())
   .subscribe(aLong -> {
    if (isStopScroll) {
     return;
    }
    isStopScroll = true;
    viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
   });
 compositeSubscription.add(subscription);
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void setUpSplash() {
  Observable.timer(2000, TimeUnit.MILLISECONDS)
      .compose(bindToLifecycle())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(aLong -> finishTask());
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

private void initPhotoView() {
  mRxManager.add(Observable.timer(100, TimeUnit.MILLISECONDS) // 直接使用glide加载的话,activity切换动画时背景短暂为默认背景色
      .compose(RxSchedulers.<Long>io_main())
      .subscribe(new Subscriber<Long>() {
        @Override
        public void onCompleted() {
          progressBar.setVisibility(View.GONE);
        }
        @Override
        public void onError(Throwable e) {
          progressBar.setVisibility(View.GONE);
        }
        @Override
        public void onNext(Long aLong) {
          ImageLoaderUtils.displayBigPhoto(getContext(),photoView,mImgSrc);
        }
      }));
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

private void setNewsDetailBodyTv(final NewsDetail newsDetail, final String newsBody) {
  mRxManager.add(Observable.timer(500, TimeUnit.MILLISECONDS)
      .compose(RxSchedulers.<Long>io_main())
      .subscribe(new Subscriber<Long>() {
        @Override
        public void onCompleted() {
          progressBar.setVisibility(View.GONE);
          fab.setVisibility(View.VISIBLE);
        }
        @Override
        public void onError(Throwable e) {
          progressBar.setVisibility(View.GONE);
        }
        @Override
        public void onNext(Long aLong) {
          setBody(newsDetail, newsBody);
        }
      }));
}

代码示例来源:origin: smuyyh/BookReader

Observable.timer(1000, TimeUnit.MILLISECONDS)
    .subscribe(new Action1<Long>() {
      @Override

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void initViewPager() {
  fragments.add(UserHomePageFragment.newInstance(mUserContributeInfo,
      mUserInterestQuanInfo, mUserCoinsInfo, mUserPlayGameInfo, mUserLiveRoomStatusInfo));
  fragments.add(UserContributeFragment.newInstance(mid, mUserContributeInfo));
  fragments.add(UserInterestQuanFragment.newInstance(mid, mUserInterestQuanInfo));
  fragments.add(UserCoinsVideoFragment.newInstance(mUserCoinsInfo));
  fragments.add(UserPlayGameFragment.newInstance(mUserPlayGameInfo));
  UserInfoDetailsPagerAdapter mAdapter = new UserInfoDetailsPagerAdapter(getSupportFragmentManager(), fragments);
  mViewPager.setOffscreenPageLimit(fragments.size());
  mViewPager.setAdapter(mAdapter);
  mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }
    @Override
    public void onPageSelected(int position) {
      measureTabLayoutTextWidth(position);
    }
    @Override
    public void onPageScrollStateChanged(int state) {
    }
  });
  Observable.timer(2000, TimeUnit.MILLISECONDS)
      .compose(bindToLifecycle())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(aLong -> setPagerTitles(), throwable -> LogUtil.all(throwable.getMessage()));
}

代码示例来源:origin: ReactiveX/RxNetty

@Test(timeout = 60000)
public void testScheduleDelay() throws Exception {
  RxJavaEventloopScheduler scheduler = new RxJavaEventloopScheduler(new NioEventLoopGroup());
  TestSubscriber<Long> testSubscriber = new TestSubscriber<>();
  Observable.timer(1, TimeUnit.MILLISECONDS, scheduler)
       .subscribe(testSubscriber);
  testSubscriber.awaitTerminalEvent();
  testSubscriber.assertNoErrors();
  testSubscriber.assertValue(0L);
}

代码示例来源:origin: ReactiveX/RxNetty

@Override
  public void evaluate() throws Throwable {
    eventLoopThread = Executors.newFixedThreadPool(1);
    channel = new EmbeddedChannel(new LoggingHandler());
    PreferCurrentEventLoopGroup eventLoopGroup = new PreferCurrentEventLoopGroup(channel.eventLoop());
    eventPublisher = MockEventPublisher.disabled();
    channel.attr(EventAttributeKeys.EVENT_PUBLISHER).set(eventPublisher);
    holder = new PreferCurrentEventLoopHolder<>(eventLoopGroup,
                          new IdleConnectionsHolderFactoryImpl());
    poolConfig = new PoolConfig<>();
    poolConfig.maxIdleTimeoutMillis(TimeUnit.DAYS.toMillis(1))
         .idleConnectionsCleanupTimer(Observable.timer(1, TimeUnit.DAYS, Schedulers.test()))
         .limitDeterminationStrategy(new MaxConnectionsBasedStrategy(1))
         .idleConnectionsHolder(holder);
    discarded = new ConcurrentLinkedQueue<>();
    released = new ConcurrentLinkedQueue<>();
    base.evaluate();
  }
};

代码示例来源:origin: ReactiveX/RxNetty

protected void init(int maxConnections, EventSource<? extends ClientEventListener> eventSource,
          EventPublisher publisher, ClientEventListener clientListener) {
  testScheduler = Schedulers.test();
  Observable<Long> idleConnCleaner = Observable.timer(1, TimeUnit.MINUTES, testScheduler);
  holder = new FIFOIdleConnectionsHolder<>();
  PoolConfig<String, String> config = new PoolConfig<>();
  config.idleConnectionsCleanupTimer(idleConnCleaner)
     .maxConnections(maxConnections)
     .idleConnectionsHolder(holder);
  Host host = new Host(new InetSocketAddress("127.0.0.1", 0));
  ConnectionProvider<String, String> cp = new EmbeddedConnectionProvider(publisher, clientListener);
  HostConnector<String, String> connector = new HostConnector<>(host, cp, eventSource, publisher,
                                 clientListener);
  provider = new PooledConnectionProviderImpl<>(config, connector);
}

代码示例来源:origin: kaku2015/ColorfulNews

private void finishActivity() {
    Observable.timer(1000, TimeUnit.MILLISECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Action1<Long>() {
          @Override
          public void call(Long aLong) {
            startActivity(new Intent(SplashActivity.this, NewsActivity.class));
            overridePendingTransition(0, android.R.anim.fade_out);
            finish();
          }
        });
  }
}

代码示例来源:origin: cn-ljb/rxjava_for_android

private void starTimer() {
    Observable.timer(3000 , TimeUnit.MILLISECONDS)
        .observeOn(AndroidSchedulers.mainThread())
        .compose(this.<Long>bindToLifecycle())
        .subscribe(new Action1<Long>() {
          @Override
          public void call(Long aLong) {
            iv_welcome.setVisibility(View.VISIBLE);
            ObjectAnimator
                .ofFloat(iv_welcome, "alpha", 0.0F, 1.0F)
                .setDuration(500)
                .start();
          }
        });
  }
}

代码示例来源:origin: THEONE10211024/RxJavaSamples

@Override
  public Observable<?> call(Throwable throwable) {
    if (++_retryCount < _maxRetries) {
      // When this Observable calls onNext, the original
      // Observable will be retried (i.e. re-subscribed).
      Timber.d("Retrying in %d ms", _retryCount * _retryDelayMillis);
      _log(String.format("Retrying in %d ms", _retryCount * _retryDelayMillis));
      return Observable.timer(_retryCount * _retryDelayMillis,
         TimeUnit.MILLISECONDS);
    }
    Timber.d("Argh! i give up");
    // Max retries hit. Just pass the error along.
    return Observable.error(throwable);
  }
});

代码示例来源:origin: THEONE10211024/RxJavaSamples

@OnClick(R.id.btn_demo_timing_1)
  public void Btn1_RunSingleTaskAfter2s() {
    _log(String.format("A1 [%s] --- BTN click", _getCurrentTimestamp()));

    Observable.timer(2, TimeUnit.SECONDS)//
//              .just(1).delay(2, TimeUnit.SECONDS)//
       .subscribe(new Observer<Long>() {
         @Override
         public void onCompleted() {
           _log(String.format("A1 [%s] XXX COMPLETE", _getCurrentTimestamp()));
         }

         @Override
         public void onError(Throwable e) {
           Timber.e(e, "something went wrong in TimingDemoFragment example");
         }

         @Override
         public void onNext(Long number) {
           _log(String.format("A1 [%s]     NEXT", _getCurrentTimestamp()));
         }
       });
  }

代码示例来源:origin: GeekGhost/Ghost

private void startCountDown() {
  Subscription rxSubscription = Observable.timer(COUNT_DOWN_TIME, TimeUnit.MILLISECONDS)
      .compose(RxUtil.<Long>rxSchedulerHelper())
      .subscribe(new Action1<Long>() {
        @Override
        public void call(Long aLong) {
          mView.jumpToMain();
        }
      });
  addSubscribe(rxSubscription);
}

代码示例来源:origin: GeekGhost/Ghost

private void putMediaId() {
  Subscription rxSubscription = Observable.timer(WAIT_TIME, TimeUnit.MILLISECONDS)
      .compose(RxUtil.<Long>rxSchedulerHelper())
      .subscribe(new Action1<Long>() {
        @Override
        public void call(Long aLong) {
          EventBus.getDefault().post(dataId, Put_DataId);
        }
      });
  addSubscribe(rxSubscription);
}

代码示例来源:origin: kaku2015/ColorfulNews

private void setNewsDetailBodyTv(final NewsDetail newsDetail, final String newsBody) {
  mSubscription = Observable.timer(500, TimeUnit.MILLISECONDS)
      .compose(TransformUtils.<Long>defaultSchedulers())
      .subscribe(new Subscriber<Long>() {
        @Override
        public void onCompleted() {
          mProgressBar.setVisibility(View.GONE);
          mFab.setVisibility(View.VISIBLE);
          YoYo.with(Techniques.RollIn).playOn(mFab);
        }
        @Override
        public void onError(Throwable e) {
          mProgressBar.setVisibility(View.GONE);
        }
        @Override
        public void onNext(Long aLong) {
          setBody(newsDetail, newsBody);
        }
      });
}

代码示例来源:origin: GeekGhost/Ghost

private void postData() {
  Subscription rxSubscription = Observable.timer(WAIT_TIME, TimeUnit.MILLISECONDS)
      .compose(RxUtil.<Long>rxSchedulerHelper())
      .subscribe(new Action1<Long>() {
        @Override
        public void call(Long aLong) {
          EventBus.getDefault().post(result, Refresh_Video_Info);
        }
      });
  addSubscribe(rxSubscription);
}

相关文章

Observable类方法