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

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

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

Observable.delay介绍

[英]Returns an Observable that emits the items emitted by the source Observable shifted forward in time by a specified delay. Error notifications from the source Observable are not delayed.

Scheduler: This version of delay operates by default on the compuation Scheduler.
[中]返回一个Observable,该Observable发出源Observable发出的项,该源Observable在时间上向前移动了指定的延迟。来自可观测源的错误通知不会延迟。
调度程序:默认情况下,此版本的延迟在计算调度程序上运行。

代码示例

代码示例来源:origin: Netflix/zuul

public Observable<String> makeSlowRequest() {
    return Observable.just("test").delay(500, TimeUnit.MILLISECONDS);
  }
}

代码示例来源:origin: Netflix/zuul

public Observable<String> makeSlowRequest() {
    return Observable.just("test").delay(500, TimeUnit.MILLISECONDS);
  }
}

代码示例来源:origin: konmik/nucleus

@Override
protected void onCreate(Bundle savedState) {
  super.onCreate(savedState);
  restartableLatestCache(GET_ITEM_REQUEST,
    () -> api.getItem(name.split("\\s+")[0], name.split("\\s+")[1], id)
      .map(it -> it.item)
      .delay(pref.getInt("delay", 0), TimeUnit.SECONDS)
      .observeOn(mainThread()),
    ItemFragment::onItem,
    ItemFragment::onNetworkError);
}

代码示例来源:origin: konmik/nucleus

@Override
public void onCreate(Bundle savedState) {
  super.onCreate(savedState);
  restartableReplay(REQUEST_ITEMS,
    () -> pageRequests.startWith(0)
      .concatMap(page ->
        api.getItems(name.split("\\s+")[0], name.split("\\s+")[1], page)
          .map(data -> new PageBundle<>(page, data))
          .delay(pref.getInt("delay", 0), TimeUnit.SECONDS)
          .observeOn(mainThread())),
    (activity, page) -> activity.onItems(page, name),
    MainFragment::onNetworkError);
}

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

@Override
public void loadData() {
 RetrofitHelper.getBangumiAPI()
   .getBangumiIndex()
   .compose(this.bindToLifecycle())
   .doOnSubscribe(this::showProgressBar)
   .subscribeOn(Schedulers.io())
   .delay(2000, TimeUnit.MILLISECONDS)
   .observeOn(AndroidSchedulers.mainThread())
   .subscribe(bangumiIndexInfo -> {
    categorys.addAll(bangumiIndexInfo.getResult().getCategory());
    finishTask();
   }, throwable -> hideProgressBar());
}

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

@Override
public void loadData() {
  RetrofitHelper.getBiliAPI()
      .getActivityCenterList(pageNum, pageSize)
      .compose(bindToLifecycle())
      .delay(1000, TimeUnit.MILLISECONDS)
      .map(ActivityCenterInfo::getList)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .doOnNext(listBeans -> {
        if (listBeans.size() < pageSize) {
          loadMoreView.setVisibility(View.GONE);
          mHeaderViewRecyclerAdapter.removeFootView();
        }
      })
      .subscribe(listBeans -> {
        activityCenters.addAll(listBeans);
        finishTask();
      }, throwable -> {
        if (mSwipeRefreshLayout.isRefreshing()) {
          mSwipeRefreshLayout.setRefreshing(false);
        }
        loadMoreView.setVisibility(View.GONE);
        ToastUtil.ShortToast("加载失败啦,请重新加载~");
      });
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Observable<String> construct() {
  executed = true;
  return Observable.just(value).delay(duration, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation())
      .doOnNext(new Action1<String>() {
        @Override
        public void call(String t1) {
          System.out.println("successfully executed");
        }
      });
}

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

@Override
public void loadData() {
  RetrofitHelper.getBangumiAPI()
      .getBangumiSchedules()
      .compose(bindToLifecycle())
      .doOnSubscribe(this::showProgressBar)
      .delay(2000, TimeUnit.MILLISECONDS)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(bangumiSchedule -> {
        bangumiSchedules.addAll(bangumiSchedule.getResult());
        finishTask();
      }, throwable -> {
        hideProgressBar();
        ToastUtil.ShortToast("加载失败啦,请重新加载~");
      });
}

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

@Override
public void loadData() {
  RetrofitHelper.getVipAPI()
      .getVipGame()
      .compose(bindToLifecycle())
      .doOnSubscribe(this::showProgressBar)
      .delay(2000, TimeUnit.MILLISECONDS)
      .flatMap(new Func1<VipGameInfo, Observable<String>>() {
        @Override
        public Observable<String> call(VipGameInfo vipGameInfo) {
          mVipGameInfoData = vipGameInfo.getData();
          return Observable.just(readAssetsJson());
        }
      })
      .compose(this.bindToLifecycle())
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(s -> {
        GameCenterInfo gameCenterInfo = new Gson().fromJson(s, GameCenterInfo.class);
        items.addAll(gameCenterInfo.getItems());
        finishTask();
      }, throwable -> hideProgressBar());
}

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

@Override
protected void loadData() {
  RetrofitHelper.getBiliAppAPI()
      .searchBangumi(content, pageNum, pageSize)
      .compose(bindToLifecycle())
      .map(SearchBangumiInfo::getData)
      .delay(1000, TimeUnit.MILLISECONDS)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .doOnNext(dataBean -> {
        if (dataBean.getItems().size() < pageSize) {
          loadMoreView.setVisibility(View.GONE);
          mHeaderViewRecyclerAdapter.removeFootView();
        }
      })
      .subscribe(dataBean -> {
        bangumis.addAll(dataBean.getItems());
        finishTask();
      }, throwable -> {
        hideSearchAnim();
        showEmptyView();
        loadMoreView.setVisibility(View.GONE);
      });
}

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

@Override
protected void loadData() {
  RetrofitHelper.getBiliAppAPI()
      .searchMovie(content, pageNum, pageSize)
      .compose(bindToLifecycle())
      .map(SearchMovieInfo::getData)
      .delay(1000, TimeUnit.MILLISECONDS)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .doOnNext(dataBean -> {
        if (dataBean.getItems().size() < pageSize) {
          loadMoreView.setVisibility(View.GONE);
          mHeaderViewRecyclerAdapter.removeFootView();
        }
      })
      .subscribe(dataBean -> {
        movies.addAll(dataBean.getItems());
        finishTask();
      }, throwable -> {
        hideSearchAnim();
        showEmptyView();
        loadMoreView.setVisibility(View.GONE);
      });
}

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

@Override
protected void loadData() {
  RetrofitHelper.getBiliAppAPI()
      .searchUpper(content, pageNum, pageSize)
      .compose(bindToLifecycle())
      .map(SearchUpperInfo::getData)
      .delay(1000, TimeUnit.MILLISECONDS)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .doOnNext(dataBean -> {
        if (dataBean.getItems().size() < pageSize) {
          loadMoreView.setVisibility(View.GONE);
          mHeaderViewRecyclerAdapter.removeFootView();
        }
      })
      .subscribe(dataBean -> {
        uppers.addAll(dataBean.getItems());
        finishTask();
      }, throwable -> {
        hideSearchAnim();
        showEmptyView();
        loadMoreView.setVisibility(View.GONE);
      });
}

代码示例来源:origin: apache/usergrid

createStreamFromWorkers( searchEdge, uniqueIdentifier ).buffer( indexTestFig.getBufferSize() )
  .delay( indexTestFig.getValidateWait(), TimeUnit.MILLISECONDS )

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

.delay(new Func1<Integer, Observable<Integer>>() {
  @Override
  public Observable<Integer> call(final Integer integer) {

代码示例来源:origin: SpikeKing/wcl-rx-cache-demo

private void fetchUpdates() {
  // 延迟3秒, 模拟效果
  mGitHubClient.getRepos("SpikeKing")
      .delay(3, TimeUnit.SECONDS)
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(mRepoDb::insertRepoList, this::fetchError, this::fetchComplete);
}

代码示例来源:origin: a-voyager/WeekToDo

private Subscription putOffTaskOneDayWithDelay(int position, TaskDetailEntity entity) {
  return Observable
      .just(1)
      .delay(2, TimeUnit.SECONDS)
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(a -> {
        putOffTaskOneDay(position, entity);
      });
}

代码示例来源:origin: boredream/DesignResCollection

public static <T> Observable<T> decorate(Observable<T> observable) {
    return observable
        .subscribeOn(Schedulers.newThread())
        .observeOn(AndroidSchedulers.mainThread())
        .delay(1, TimeUnit.SECONDS, AndroidSchedulers.mainThread()); // FIXME 模拟延迟,用于观察加载框等效果
  }
}

代码示例来源:origin: NightscoutFoundation/xDrip

@NonNull
@Override
public Observable<Void> asObservable(BluetoothGatt bluetoothGatt,
                   RxBleGattCallback rxBleGattCallback,
                   Scheduler scheduler) throws Throwable {
  return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt))
      .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation())
      .subscribeOn(scheduler);
}

代码示例来源:origin: jamorham/xDrip-plus

@NonNull
@Override
public Observable<Void> asObservable(BluetoothGatt bluetoothGatt,
                   RxBleGattCallback rxBleGattCallback,
                   Scheduler scheduler) throws Throwable {
  return Observable.fromCallable(() -> refreshDeviceCache(bluetoothGatt))
      .delay(delay_ms, TimeUnit.MILLISECONDS, Schedulers.computation())
      .subscribeOn(scheduler);
}

代码示例来源:origin: nurkiewicz/rxjava-book-examples

@Test
public void sample_355() throws Exception {
  Observable<String> fast = interval(10, MILLISECONDS)
      .map(x -> "F" + x)
      .delay(100, MILLISECONDS)
      .startWith("FX");
  Observable<String> slow = interval(17, MILLISECONDS).map(x -> "S" + x);
  slow
      .withLatestFrom(fast, (s, f) -> s + ":" + f)
      .forEach(System.out::println);
}

相关文章

Observable类方法