After a successful rewrite of my sync codebase to async with an enormous help of RxJava,
I started to wonder why it doesn't have a Future type that represents a one-time task rather than an asynchronous push-based collection of data.
I have seen a few Netflix presentations on RxJava saying that Observable can be used for both async collections and one-time async tasks, which is nice,
but it's a little confusing when I have an Observable<T> and I can't really tell, by looking at the type, whether it will emit a series of data or just a single object.
For example, my Observable wrapper on Netflix Curator has its interface like this:
Observable<String> watch(String path);
Observable<String> get(String path);
Observable<Void> delete(String path);
The method watch returns an infinite stream of String objects which is emitted every time the ZooKeeper node's data is updated,
whereas the second and third ones are for one-time asynchronous tasks, which will emit a single response when the task finishes, and then complete the Observable.
I wish I had a 'Future' type to distinguish these from a collection Observable, so that I can notice how an asynchronous operation will behave just by looking at the type, and become more typesafe in a sense.
I am aware that this whole project is about the idea of Observable as the async Iterable, and there are Scala Future, Akka future, Guava ListenableFuture and Java 8's CompletableFuture for my concerns,
But I just can't give up all the powerful functionalities that Rx provides, and I also don't want to write and use messy wrappers over those external Future classes.
If there is a rx.Future type that is interopable with rx.Observable, possibly as a subclass of rx.Observable,
the interfaces can still be consistent, like merge(Future...) returning an Observable and zip(Future...) returning a Future, Future.map/flatMap returns Future while Observable.map/flatMap returns Observable, and so on.
Is there some release notes/discussions that explain why RxJava didn't adopt this strategy? I know my whole idea might be wrong so advises are appreciated.
Thanks,
Jong Wook