Last active
January 3, 2016 05:28
-
-
Save akarnokd/8415517 to your computer and use it in GitHub Desktop.
ObsurvableExamples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package rx; | |
import java.util.Arrays; | |
import java.util.concurrent.TimeUnit; | |
import rx.Obsurvable.OperatorSubscription; | |
import rx.schedulers.Schedulers; | |
/** | |
* | |
*/ | |
public class ObsurvableExamples { | |
public static void main(String[] args) throws Exception { | |
OperatorSubscription os = new OperatorSubscription(); | |
Schedulers.computation().schedule(() -> { | |
System.out.println("Unsubscribing"); | |
os.unsubscribe(); | |
}, 2, TimeUnit.SECONDS | |
); | |
Obsurvable.from(Arrays.asList(1, 2, 3)).repeat().subscribe(os, new Observer<Integer>() { | |
int j = 0; | |
@Override | |
public void onNext(Integer args) { | |
if (j % 3000000 == 0) { | |
System.out.println(args); | |
} | |
j++; | |
} | |
@Override | |
public void onError(Throwable e) { | |
e.printStackTrace(); | |
} | |
@Override | |
public void onCompleted() { | |
System.out.println("-Done-"); | |
} | |
}); | |
Thread.sleep(3000); | |
Obsurvable.from(1).repeat().take(10000).zip( | |
Obsurvable.from(2).repeat().take(5), (a, b) -> a + b).take(2).subscribe(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment