当前位置: 首页>>代码示例>>Java>>正文


Java Observable.interval方法代码示例

本文整理汇总了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);
    }
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:21,代码来源:Ch2_35.java

示例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);
    }
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:24,代码来源:Ch2_34.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:14,代码来源:Ch4_14.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:10,代码来源:Ch7_7.java

示例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();
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:19,代码来源:LongpollService.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:11,代码来源:Ch4_16.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:11,代码来源:Ch4_15.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:36,代码来源:Ch10_13.java

示例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);
    }
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:8,代码来源:Ch1_3.java

示例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);
    }
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:13,代码来源:Ch2_18.java

示例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);
    }
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:14,代码来源:Ch2_33.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:13,代码来源:Ch7_11.java

示例13: Zorro

import io.reactivex.Observable; //导入方法依赖的package包/类
public Zorro(final PluginConfig pluginConfig) {
    this.pluginConfig = pluginConfig;

    heartBeat = Observable.interval(0L,
                                    pluginConfig.zorroProgressInterval(),
                                    TimeUnit.MILLISECONDS);
}
 
开发者ID:juxeii,项目名称:dztools,代码行数:8,代码来源:Zorro.java

示例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));
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:9,代码来源:UploadQueueStore.java

示例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>"))
    );
}
 
开发者ID:OlegDokuka,项目名称:reactive-playing,代码行数:10,代码来源:TickTack.java


注:本文中的io.reactivex.Observable.interval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。