本文整理了Java中io.reactivex.Observable.throttleFirst()
方法的一些代码示例,展示了Observable.throttleFirst()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.throttleFirst()
方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:throttleFirst
[英]Returns an Observable that emits only the first item emitted by the source ObservableSource during sequential time windows of a specified duration.
This differs from #throttleLast in that this only tracks passage of time whereas #throttleLast ticks at scheduled intervals.
Scheduler: throttleFirst operates by default on the computation Scheduler.
[中]返回在指定持续时间的连续时间窗口内仅发射源ObservableSource发射的第一项的Observable。
这与#throttleLast的不同之处在于,它只跟踪时间的流逝,而#throttleLast按预定的间隔滴答作响。
调度程序:throttleFirst默认在计算调度程序上运行。
代码示例来源:origin: amitshekhariitbhu/RxJava2-Android-Samples
private void doSomeWork() {
getObservable()
.throttleFirst(500, TimeUnit.MILLISECONDS)
// Run on a background thread
.subscribeOn(Schedulers.io())
// Be notified on the main thread
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getObserver());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void throttleFirstSchedulerNull() {
just1.throttleFirst(1, TimeUnit.SECONDS, null);
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Returns an Observable that emits only the first item emitted by the source ObservableSource during sequential
* time windows of a specified duration.
* <p>
* This differs from {@link #throttleLast} in that this only tracks passage of time whereas
* {@link #throttleLast} ticks at scheduled intervals.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/throttleFirst.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code throttleFirst} operates by default on the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param windowDuration
* time to wait before emitting another item after emitting the last item
* @param unit
* the unit of time of {@code windowDuration}
* @return an Observable that performs the throttle operation
* @see <a href="http://reactivex.io/documentation/operators/sample.html">ReactiveX operators documentation: Sample</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public final Observable<T> throttleFirst(long windowDuration, TimeUnit unit) {
return throttleFirst(windowDuration, unit, Schedulers.computation());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Observable.just(1).throttleFirst(1, TimeUnit.DAYS));
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void throttleFirstUnitNull() {
just1.throttleFirst(1, null, Schedulers.single());
}
代码示例来源:origin: redisson/redisson
/**
* Returns an Observable that emits only the first item emitted by the source ObservableSource during sequential
* time windows of a specified duration.
* <p>
* This differs from {@link #throttleLast} in that this only tracks passage of time whereas
* {@link #throttleLast} ticks at scheduled intervals.
* <p>
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/throttleFirst.png" alt="">
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code throttleFirst} operates by default on the {@code computation} {@link Scheduler}.</dd>
* </dl>
*
* @param windowDuration
* time to wait before emitting another item after emitting the last item
* @param unit
* the unit of time of {@code windowDuration}
* @return an Observable that performs the throttle operation
* @see <a href="http://reactivex.io/documentation/operators/sample.html">ReactiveX operators documentation: Sample</a>
*/
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public final Observable<T> throttleFirst(long windowDuration, TimeUnit unit) {
return throttleFirst(windowDuration, unit, Schedulers.computation());
}
代码示例来源:origin: iMeiji/Toutiao
@Override
protected void onBindViewHolder(@NonNull final ViewHolder holder, @NonNull final MediaChannelBean item) {
try {
final Context context = holder.itemView.getContext();
String url = item.getAvatar();
ImageLoader.loadCenterCrop(context, url, holder.cv_avatar, R.color.viewBackground);
holder.tv_mediaName.setText(item.getName());
holder.tv_descText.setText(item.getDescText());
RxView.clicks(holder.itemView)
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(o -> MediaHomeActivity.launch(item.getId()));
} catch (Exception e) {
ErrorAction.print(e);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void throttleFirstDefaultScheduler() {
Observable.just(1).throttleFirst(100, TimeUnit.MILLISECONDS)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testThrottlingWithCompleted() {
Observable<String> source = Observable.unsafeCreate(new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> innerObserver) {
innerObserver.onSubscribe(Disposables.empty());
publishNext(innerObserver, 100, "one"); // publish as it's first
publishNext(innerObserver, 300, "two"); // skip as it's last within the first 400
publishNext(innerObserver, 900, "three"); // publish
publishNext(innerObserver, 905, "four"); // skip
publishCompleted(innerObserver, 1000); // Should be published as soon as the timeout expires.
}
});
Observable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("one");
inOrder.verify(observer, times(0)).onNext("two");
inOrder.verify(observer, times(1)).onNext("three");
inOrder.verify(observer, times(0)).onNext("four");
inOrder.verify(observer, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testThrottlingWithError() {
Observable<String> source = Observable.unsafeCreate(new ObservableSource<String>() {
@Override
public void subscribe(Observer<? super String> innerObserver) {
innerObserver.onSubscribe(Disposables.empty());
Exception error = new TestException();
publishNext(innerObserver, 100, "one"); // Should be published since it is first
publishNext(innerObserver, 200, "two"); // Should be skipped since onError will arrive before the timeout expires
publishError(innerObserver, 300, error); // Should be published as soon as the timeout expires.
}
});
Observable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(400, TimeUnit.MILLISECONDS);
inOrder.verify(observer).onNext("one");
inOrder.verify(observer).onError(any(TestException.class));
inOrder.verifyNoMoreInteractions();
}
代码示例来源:origin: iMeiji/Toutiao
@Override
protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final WendaContentBean.AnsListBean item) {
try {
String iv_user_avatar = item.getUser().getAvatar_url();
ImageLoader.loadCenterCrop(holder.itemView.getContext(), iv_user_avatar, holder.iv_user_avatar, R.color.viewBackground);
String tv_user_name = item.getUser().getUname();
String tv_like_count = item.getDigg_count() + "";
String tv_abstract = item.getContent_abstract().getText();
holder.tv_user_name.setText(tv_user_name);
holder.tv_like_count.setText(tv_like_count);
holder.tv_abstract.setText(tv_abstract);
RxView.clicks(holder.itemView)
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(o -> WendaDetailActivity.launch(item));
} catch (Exception e) {
ErrorAction.print(e);
}
}
代码示例来源:origin: iMeiji/Toutiao
@Override
protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull final WendaArticleDataBean item) {
try {
String tv_title = item.getQuestionBean().getTitle();
String tv_answer_count = item.getQuestionBean().getNormal_ans_count() + item.getQuestionBean().getNice_ans_count() + "回答";
String tv_datetime = item.getQuestionBean().getCreate_time() + "";
if (!TextUtils.isEmpty(tv_datetime)) {
tv_datetime = TimeUtil.getTimeStampAgo(tv_datetime);
}
String tv_content = item.getAnswerBean().getAbstractX();
holder.tv_title.setText(tv_title);
holder.tv_title.setTextSize(SettingUtil.getInstance().getTextSize());
holder.tv_answer_count.setText(tv_answer_count);
holder.tv_time.setText(tv_datetime);
holder.tv_content.setText(tv_content);
RxView.clicks(holder.itemView)
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(o -> WendaContentActivity.launch(item.getQuestionBean().getQid() + ""));
} catch (Exception e) {
ErrorAction.print(e);
}
}
代码示例来源:origin: iMeiji/Toutiao
@Override
protected void onBindViewHolder(@NonNull final ViewHolder holder, @NonNull final WendaArticleDataBean item) {
final Context context = holder.itemView.getContext();
try {
String url = item.getExtraBean().getWenda_image().getLarge_image_list().get(0).getUrl();
ImageLoader.loadCenterCrop(context, url, holder.iv_image_big, R.color.viewBackground);
final String tv_title = item.getQuestionBean().getTitle();
String tv_answer_count = item.getQuestionBean().getNormal_ans_count() + item.getQuestionBean().getNice_ans_count() + "回答";
String tv_datetime = item.getQuestionBean().getCreate_time() + "";
if (!TextUtils.isEmpty(tv_datetime)) {
tv_datetime = TimeUtil.getTimeStampAgo(tv_datetime);
}
holder.tv_title.setText(tv_title);
holder.tv_title.setTextSize(SettingUtil.getInstance().getTextSize());
holder.tv_answer_count.setText(tv_answer_count);
holder.tv_time.setText(tv_datetime);
RxView.clicks(holder.itemView)
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(o -> WendaContentActivity.launch(item.getQuestionBean().getQid() + ""));
} catch (Exception e) {
ErrorAction.print(e);
}
}
代码示例来源:origin: iMeiji/Toutiao
.throttleFirst(1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.switchMap((Function<String, ObservableSource<NewsContentBean>>) s -> RetrofitFactory.getRetrofit().create(INewsApi.class).getNewsContent(s))
代码示例来源:origin: iMeiji/Toutiao
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(o -> NewsContentActivity.launch(item, finalImgUrl));
} catch (Exception e) {
代码示例来源:origin: iMeiji/Toutiao
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(o -> NewsContentActivity.launch(item));
} catch (Exception e) {
代码示例来源:origin: iMeiji/Toutiao
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(o -> WendaContentActivity.launch(item.getQuestionBean().getQid() + ""));
} catch (Exception e) {
代码示例来源:origin: iMeiji/Toutiao
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(o -> {
MultiNewsArticleDataBean bean = new MultiNewsArticleDataBean();
代码示例来源:origin: iMeiji/Toutiao
.throttleFirst(1, TimeUnit.SECONDS)
.subscribe(o -> {
WendaContentBean.AnsListBean ansBean = new WendaContentBean.AnsListBean();
代码示例来源:origin: iMeiji/Toutiao
RxView.clicks(tv_refresh)
.throttleFirst(1, TimeUnit.SECONDS)
.as(this.bindAutoDispose())
.subscribe(o -> {
内容来源于网络,如有侵权,请联系作者删除!