Skip to content

Instantly share code, notes, and snippets.

@ursimon
Forked from antslava/RxJavaExample.java
Created February 15, 2017 15:54
Show Gist options
  • Select an option

  • Save ursimon/dfa88a8144098f685aedc20b9c4f06f5 to your computer and use it in GitHub Desktop.

Select an option

Save ursimon/dfa88a8144098f685aedc20b9c4f06f5 to your computer and use it in GitHub Desktop.

Revisions

  1. @antslava antslava created this gist Feb 15, 2017.
    52 changes: 52 additions & 0 deletions RxJavaExample.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    package com.antmobile.java;

    import rx.Observable;
    import rx.Subscriber;
    import rx.schedulers.Schedulers;

    public class FirstTempClass {

    public static void main(String[] args) {
    final Observable<Long> observable = Observable.create(new Observable.OnSubscribe<Long>() {
    public void call(Subscriber<? super Long> subscriber) {
    subscriber.onNext(System.nanoTime());
    }
    })
    .subscribeOn(Schedulers.io())
    .observeOn(Schedulers.io())
    .share();

    // First
    observable.subscribe(new Subscriber<Long>() {
    public void onCompleted() {
    System.out.println("");
    }

    public void onError(Throwable e) {
    System.out.println();
    }

    public void onNext(Long aLong) {
    System.out.println("first:= " + aLong);
    }
    });

    // Second
    observable.subscribe(new Subscriber<Long>() {
    public void onCompleted() {
    System.out.println();
    }

    public void onError(Throwable e) {
    System.out.println();
    }

    public void onNext(Long aLong) {
    System.out.println("second:= " + aLong);
    }
    });
    while (true) {

    }
    }
    }