Skip to content

Commit

Permalink
Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Jan 9, 2023
1 parent 9a44a79 commit 1d56500
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,37 @@ private static void safelyExecuteLocked(final StreamObserver<?> observer,
}
}

/**
* Sends one message to the stream, ignoring any errors that may happen during that call.
*
* @param observer the stream to complete
* @param message the message to send on this stream
* @param <T> the type of message that the stream handles
*/
public static <T> void safelyOnNext(StreamObserver<T> observer, T message) {
safelyExecuteLocked(observer, () -> observer.onNext(message));
}

/**
* Sends one message and then completes the stream, ignoring any errors that may happen during these calls. Useful
* for unary responses.
*
* @param observer the stream to complete
* @param message the last message to send on this stream before completing
* @param <T> the type of message that the stream handles
*/
public static <T> void safelyComplete(StreamObserver<T> observer, T message) {
safelyExecuteLocked(observer, () -> {
observer.onNext(message);
observer.onCompleted();
});
}

/**
* Completes the stream, ignoring any errors that may happen during this call.
*
* @param observer the stream to complete
*/
public static void safelyComplete(StreamObserver<?> observer) {
safelyExecuteLocked(observer, observer::onCompleted);
}
Expand Down

0 comments on commit 1d56500

Please sign in to comment.