Module io.jooby
Package io.jooby

Interface Sender


public interface Sender
Non-blocking sender. Reactive responses uses this class to send partial data in non-blocking manner.

RxJava example:


 Sender sender = ctx.getSender();

 Flux.fromCallable(...)
   .subscribe(new Subscriber () {

     onSubscribe(Subscription s) {
       this.subscription = s;
       this.subscription.request(1);
     }

     onNext(Object next) {
       sender.write(next, (ctx, cause) -> {
         subscription.request(1);
       });
     }

     onError(Throwable error) {
       subscription.cancel();
     }

     onComplete() {
       sender.close();
     }
   })

 
Since:
2.0.0
Author:
edgar
  • Method Details

    • write

      @NonNull default Sender write(@NonNull String data, @NonNull Sender.Callback callback)
      Write a string chunk. Chunk is flushed immediately.
      Parameters:
      data - String chunk.
      callback - Callback.
      Returns:
      This sender.
    • write

      @NonNull default Sender write(@NonNull String data, @NonNull Charset charset, @NonNull Sender.Callback callback)
      Write a string chunk. Chunk is flushed immediately.
      Parameters:
      data - String chunk.
      charset - Charset.
      callback - Callback.
      Returns:
      This sender.
    • write

      @NonNull Sender write(@NonNull byte[] data, @NonNull Sender.Callback callback)
      Write a bytes chunk. Chunk is flushed immediately.
      Parameters:
      data - Bytes chunk.
      callback - Callback.
      Returns:
      This sender.
    • write

      @NonNull Sender write(@NonNull DataBuffer data, @NonNull Sender.Callback callback)
    • close

      void close()
      Close the sender.