Last active
August 29, 2015 14:18
-
-
Save jbrisbin/48ad8f8a254d7d7705fa to your computer and use it in GitHub Desktop.
Using Buffer and Promise rather than raw Publisher contracts
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
interface Buffer<B> extends Publisher<B> { | |
<NEWB> Buffer<NEWB> intercept(Interceptor<B, NEWB> fn); | |
Buffer<B> append(Buffer<B> buff); | |
Buffer<B> append(B obj); | |
} | |
interface Promise<T> extends Subscriber<T> { | |
boolean isComplete(); | |
boolean isError(); | |
T getValue(); | |
Throwable getCause(); | |
Promise<T> onSuccess(Handler<T> callback); | |
Promise<T> onError(Handler<Throwable> callback); | |
} | |
class Promises { | |
static <T> Publisher<T> toPublisher(Promise<T> promise); | |
} | |
interface Connection { | |
Buffer<Object> receive(); | |
Promise<Void> send(Buffer<Object> buff); | |
} | |
server | |
.intercept(c -> new ConnectionWrapperImpl(c)) | |
.handler(conn -> { | |
conn.receive() | |
.intercept(converter::convertToPojo) | |
.subscribe(new Subscriber<Pojo>() {}); | |
Buffer<Pojo> b = pool.alloc(Pojo.class); | |
b.append(new Pojo()); | |
toPublisher(conn.send(b.intercept(convert::convertToBuffer))) | |
.subscribe(new Subscriber<Void>() {}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment