本文整理汇总了Java中io.reactivex.Observable.interval方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.interval方法的具体用法?Java Observable.interval怎么用?Java Observable.interval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Observable
的用法示例。
在下文中一共展示了Observable.interval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> seconds =
Observable.interval(1, TimeUnit.SECONDS);
//subscribe and capture disposables
Disposable disposable1 =
seconds.subscribe(l -> System.out.println("Observer 1: " +
l));
Disposable disposable2 =
seconds.subscribe(l -> System.out.println("Observer 2: " +
l));
//put both disposables into CompositeDisposable
disposables.addAll(disposable1, disposable2);
//sleep 5 seconds
sleep(5000);
//dispose all disposables
disposables.dispose();
//sleep 5 seconds to prove
//there are no more emissions
sleep(5000);
}
示例2: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> source =
Observable.interval(1, TimeUnit.SECONDS);
ResourceObserver<Long> myObserver = new
ResourceObserver<Long>() {
@Override
public void onNext(Long value) {
System.out.println(value);
}
@Override
public void onError(Throwable e) {
e.printStackTrace();
}
@Override
public void onComplete() {
System.out.println("Done!");
}
};
//capture Disposable
Disposable disposable = source.subscribeWith(myObserver);
}
示例3: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<String> strings =
Observable.just("Alpha", "Beta", "Gamma", "Delta",
"Epsilon");
Observable<Long> seconds =
Observable.interval(1, TimeUnit.SECONDS);
Observable.zip(strings, seconds, (s, l) -> s)
.subscribe(s ->
System.out.println("Received " + s +
" at " + LocalTime.now())
);
sleep(6000);
}
示例4: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> cutOffs =
Observable.interval(1, TimeUnit.SECONDS);
Observable.interval(300, TimeUnit.MILLISECONDS)
.map(i -> (i + 1) * 300) // map to elapsed time
.buffer(cutOffs)
.subscribe(System.out::println);
sleep(5000);
}
示例5: onCreate
import io.reactivex.Observable; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
this.mRegisteredPeers = new SparseArray<>(2);
this.mActiveLongpolls = new SparseArray<>(1);
Logger.d(TAG, "Service created");
mCompositeDisposable.add(Settings.get()
.accounts()
.observeChanges()
.observeOn(Injection.provideMainThreadScheduler())
.subscribe(this::onAccountChange));
mShutdownObservable = Observable.interval(INTERVAL, INTERVAL, TimeUnit.MILLISECONDS,
Injection.provideMainThreadScheduler());
restartShutdownDelay();
}
示例6: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> source1 =
Observable.interval(300, TimeUnit.MILLISECONDS);
Observable<Long> source2 =
Observable.interval(1, TimeUnit.SECONDS);
source2.withLatestFrom(source1,
(l1, l2) -> "SOURCE 2: " + l1 + " SOURCE 1: " + l2
).subscribe(System.out::println);
sleep(3000);
}
示例7: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> source1 =
Observable.interval(300, TimeUnit.MILLISECONDS);
Observable<Long> source2 =
Observable.interval(1, TimeUnit.SECONDS);
Observable.combineLatest(source1, source2,
(l1, l2) -> "SOURCE 1: " + l1 + " SOURCE 2: " + l2)
.subscribe(System.out::println);
sleep(3000);
}
示例8: usingTestScheduler
import io.reactivex.Observable; //导入方法依赖的package包/类
@Test
public void usingTestScheduler() {
//Declare TestScheduler
TestScheduler testScheduler = new TestScheduler();
//Declare TestObserver
TestObserver<Long> testObserver = new TestObserver<>();
//Declare Observable emitting every 1 minute
Observable<Long> minuteTicker =
Observable.interval(1, TimeUnit.MINUTES,
testScheduler);
//Subscribe to TestObserver
minuteTicker.subscribe(testObserver);
//Fast forward by 30 seconds
testScheduler.advanceTimeBy(30, TimeUnit.SECONDS);
//Assert no emissions have occurred yet
testObserver.assertValueCount(0);
//Fast forward to 70 seconds after subscription
testScheduler.advanceTimeTo(70, TimeUnit.SECONDS);
//Assert the first emission has occurred
testObserver.assertValueCount(1);
//Fast Forward to 90 minutes after subscription
testScheduler.advanceTimeTo(90, TimeUnit.MINUTES);
//Assert 90 emissions have occurred
testObserver.assertValueCount(90);
}
示例9: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> secondIntervals =
Observable.interval(1, TimeUnit.SECONDS);
secondIntervals.subscribe(s -> System.out.println(s));
/* Hold main thread for 5 secondsso Observable above has chance to fire */
sleep(5000);
}
示例10: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> seconds = Observable.interval(1,
TimeUnit.SECONDS);
//Observer 1
seconds.subscribe(l -> System.out.println("Observer 1: " + l));
//sleep 5 seconds
sleep(5000);
//Observer 2
seconds.subscribe(l -> System.out.println("Observer 2: " + l));
//sleep 5 seconds
sleep(5000);
}
示例11: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> seconds =
Observable.interval(1, TimeUnit.SECONDS);
Disposable disposable =
seconds.subscribe(l -> System.out.println("Received: " + l));
//sleep 5 seconds
sleep(5000);
//dispose and stop emissions
disposable.dispose();
//sleep 5 seconds to prove
//there are no more emissions
sleep(5000);
}
示例12: main
import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
Observable<Long> cutOffs =
Observable.interval(1, TimeUnit.SECONDS);
Observable.interval(300, TimeUnit.MILLISECONDS)
.map(i -> (i + 1) * 300) // map to elapsed time
.window(cutOffs)
.flatMapSingle(obs -> obs.reduce("", (total, next) ->
total
+ (total.equals("") ? "" : "|") + next))
.subscribe(System.out::println);
sleep(5000);
}
示例13: Zorro
import io.reactivex.Observable; //导入方法依赖的package包/类
public Zorro(final PluginConfig pluginConfig) {
this.pluginConfig = pluginConfig;
heartBeat = Observable.interval(0L,
pluginConfig.zorroProgressInterval(),
TimeUnit.MILLISECONDS);
}
示例14: UploadQueueStore
import io.reactivex.Observable; //导入方法依赖的package包/类
@SuppressLint("UseSparseArrays")
UploadQueueStore(@NonNull AppStores base) {
super(base);
this.statusUpdatePublishSubject = PublishSubject.create();
this.queueUpdatesPublishSubject = PublishSubject.create();
this.timer = Observable.interval(0L, PROGRESS_LOOKUP_DELAY, TimeUnit.MILLISECONDS);
this.progress = Collections.synchronizedMap(new HashMap<>(0));
}
示例15: clock
import io.reactivex.Observable; //导入方法依赖的package包/类
private static Observable<Long> clock() {
Observable<Long> fast = Observable.interval(1, TimeUnit.SECONDS);
Observable<Long> slow = Observable.interval(3, TimeUnit.SECONDS);
return Observable.merge(
slow.filter(t -> isSlowTickTime()).doOnEach(w->System.out.println("<SLOW>")),
fast.filter(t -> !isSlowTickTime()).doOnEach(w->System.out.println("<FAST>"))
);
}