本文整理了Java中rx.Observable.repeat()
方法的一些代码示例,展示了Observable.repeat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.repeat()
方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:repeat
[英]Returns an Observable that repeats the sequence of items emitted by the source Observable indefinitely.
Scheduler: repeat operates by default on the trampoline Scheduler.
[中]返回一个Observable,它无限期地重复源Observable发出的项目序列。
调度程序:默认情况下,repeat在蹦床调度程序上运行。
代码示例来源:origin: xuhongv/SmartHome
public void startAnimation(final int rankWidth, final int rankHeight) {
Observable.timer((long)this.innerDelay, TimeUnit.MILLISECONDS).repeat((long)((int)(Math.random() * (double)(this.maxHeartNum - this.minHeartNum)) + this.minHeartNum)).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() {
public void call(Long aLong) {
BubbleView.this.bubbleAnimation(rankWidth, rankHeight);
}
});
}
代码示例来源:origin: davidmoten/rxjava-extras
public static Observable<Double> solveWithNewtonsMethod(final Func1<Double, Double> f,
final Func1<Double, Double> dfdx, double x0) {
return Observable.just(1).repeat().scan(x0, new Func2<Double, Integer, Double>() {
@Override
public Double call(Double xn, Integer n) {
return xn - f.call(xn) / dfdx.call(xn);
}
});
}
代码示例来源:origin: henrymorgen/android-advanced-light
private void repeat() {
Observable.range(0, 3)
.repeat(2)
.subscribe(new Action1<Integer>() {
@Override
public void call(Integer integer) {
Log.d(TAG, "repeat:" +integer.intValue());
}
});
}
代码示例来源:origin: com.github.davidmoten/rxjava-extras
public Builder delay(Long delay, final TimeUnit unit) {
this.delays = Observable.just(delay).map(toMillis(unit)).repeat();
return this;
}
代码示例来源:origin: xuhongv/SmartHome
public void startAnimation(final int rankWidth, final int rankHeight, int count) {
Observable.timer((long)this.innerDelay, TimeUnit.MILLISECONDS).repeat((long)count).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() {
public void call(Long aLong) {
BubbleView.this.bubbleAnimation(rankWidth, rankHeight);
}
});
}
代码示例来源:origin: xuhongv/SmartHome
public void startAnimation(final int rankWidth, final int rankHeight, int delay, int count) {
Observable.timer((long)delay, TimeUnit.MILLISECONDS).repeat((long)count).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() {
public void call(Long aLong) {
BubbleView.this.bubbleAnimation(rankWidth, rankHeight);
}
});
}
代码示例来源:origin: davidmoten/rxjava-extras
public Builder delay(Long delay, final TimeUnit unit) {
this.delays = Observable.just(delay).map(toMillis(unit)).repeat();
return this;
}
代码示例来源:origin: com.github.davidmoten/rxjava-extras
public static Observable<Double> solveWithNewtonsMethod(final Func1<Double, Double> f,
final Func1<Double, Double> dfdx, double x0) {
return Observable.just(1).repeat().scan(x0, new Func2<Double, Integer, Double>() {
@Override
public Double call(Double xn, Integer n) {
return xn - f.call(xn) / dfdx.call(xn);
}
});
}
代码示例来源:origin: leandroBorgesFerreira/UpdatableMap
public Observable<Collection<Car>> getCarsObservable(){
return Observable.interval(UPDATE_FREQUENCY_SECONDS, TimeUnit.SECONDS)
.flatMap(n -> ServiceGenerator.createService(MapClient.class).getCars().map(Map::values))
.repeat()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
}
代码示例来源:origin: marcoRS/rxjava-essentials
private void loadList(List<AppInfo> apps) {
mRecyclerView.setVisibility(View.VISIBLE);
Observable<AppInfo> fullOfDuplicates = Observable.from(apps).take(3).repeat(3);
fullOfDuplicates.distinct().subscribe(new Observer<AppInfo>() {
@Override public void onCompleted() {
mSwipeRefreshLayout.setRefreshing(false);
}
@Override public void onError(Throwable e) {
Toast.makeText(getActivity(), "Something went south!", Toast.LENGTH_SHORT).show();
mSwipeRefreshLayout.setRefreshing(false);
}
@Override public void onNext(AppInfo appInfo) {
mAddedApps.add(appInfo);
mAdapter.addApplication(mAddedApps.size() - 1, appInfo);
}
});
}
}
代码示例来源:origin: com.netflix.spinnaker.orca/orca-core
protected void startPolling() {
subscription = Observable
.timer(getPollingInterval(), getPollingIntervalUnit(), scheduler)
.repeat()
.filter(interval -> tryAcquireLock())
.subscribe(interval -> {
try {
MDC.put(AGENT_MDC_KEY, this.getClass().getSimpleName());
tick();
} catch (Exception e) {
log.error("Error running agent tick", e);
} finally {
MDC.remove(AGENT_MDC_KEY);
}
});
}
代码示例来源:origin: nurkiewicz/rxjava-book-examples
static <T> Observable<T> odd(Observable<T> upstream) {
Observable<Boolean> trueFalse = just(true, false).repeat();
return upstream
.zipWith(trueFalse, Pair::of)
.filter(Pair::getRight)
.map(Pair::getLeft);
}
代码示例来源:origin: nurkiewicz/rxjava-book-examples
private <T> Observable.Transformer<T, T> odd() {
Observable<Boolean> trueFalse = just(true, false).repeat();
return upstream -> upstream
.zipWith(trueFalse, Pair::of)
.filter(Pair::getRight)
.map(Pair::getLeft);
}
代码示例来源:origin: Petikoch/Java_MVVM_with_Swing_and_RxJava_Examples
public Observable<String> infos() {
Observable<String> texts = Observable.just("Hello World", "Hallo Welt", "Bonjour le monde", "Ciao mondo").repeat();
Observable<Long> trigger = Observable.interval(1, TimeUnit.SECONDS);
return Observable.zip(texts, trigger, (text, aLong) -> text).doOnNext(text -> SysOutUtils.sysout("Sending: " + text));
}
代码示例来源:origin: nurkiewicz/rxjava-book-examples
@Test
public void sample_120() throws Exception {
Random random = new Random();
Observable
.defer(() -> just(random.nextGaussian()))
.repeat(1000)
.buffer(100, 1)
.map(this::averageOfList)
.subscribe(System.out::println);
}
代码示例来源:origin: akarnokd/akarnokd-misc
@Test
public void test() throws Exception {
Observable<String> delay = Observable.just("")
.switchMap(dummy -> Observable.timer(randomTime(), TimeUnit.SECONDS))
.map( a -> String.valueOf(a) )
.repeat();
Observable<String> messages = Observable.just("Test") //eventually lines from a file...
.repeat();
messages.zipWith(delay, (d, msg) -> ""+d+" "+msg ).subscribe( System.out::println );
Thread.sleep(10000);
}
}
代码示例来源:origin: nurkiewicz/rxjava-book-examples
@Test
public void sample_589() throws Exception {
Observable<Boolean> trueFalse = Observable.just(true, false).repeat();
Observable<Integer> upstream = Observable.range(30, 8);
Observable<Integer> downstream = upstream
.zipWith(trueFalse, Pair::of)
.filter(Pair::getRight)
.map(Pair::getLeft);
}
代码示例来源:origin: akarnokd/akarnokd-misc
@Test
public void decode() {
byte[] bytes = new byte[16];
Arrays.fill(bytes, (byte)65);
byte[] bytes2 = new byte[16];
Arrays.fill(bytes, (byte)65);
bytes[15] = 10;
Observable<byte[]> data = Observable.just(bytes, bytes, bytes2).repeat(500);
StringObservable.decode(data, StandardCharsets.UTF_8)
.observeOn(Schedulers.computation(), false, 1)
.toBlocking()
.subscribe(System.out::println);
}
代码示例来源:origin: nurkiewicz/rxjava-book-examples
@Test
public void sample_600() throws Exception {
Observable<Boolean> trueFalse = Observable.just(true, false).repeat();
Observable<Integer> upstream = Observable.range(30, 8);
upstream.zipWith(trueFalse, (t, bool) ->
bool ? just(t) : empty())
.flatMap(obs -> obs);
}
}
代码示例来源:origin: nurkiewicz/rxjava-book-examples
@Test
public void sample_112() throws Exception {
Observable
.range(1, 4)
.repeat()
.lift(toStringOfOdd())
.take(3)
.subscribe(
System.out::println,
Throwable::printStackTrace,
() -> System.out.println("Completed")
);
}
}
内容来源于网络,如有侵权,请联系作者删除!