當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。