Skip to content

Instantly share code, notes, and snippets.

@akarnokd
Last active January 3, 2016 05:28
Show Gist options
  • Save akarnokd/8415517 to your computer and use it in GitHub Desktop.
Save akarnokd/8415517 to your computer and use it in GitHub Desktop.
ObsurvableExamples
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