On 10/20/2015 12:49 PM, Simone Bordet wrote:
>CharBuffer message = ... get buffer from pool or create new one ...
>
>... fill message with data ...
>
>CompletionStage<CharBuffer> cs = listener.onText(..., message, ...);
>
>if (cs != null) {
> cs.thenAccept(cb -> {
> if (cb != null) {
> .... return cb to buffer pool ...
> }
> });
>}
>
>What do you think?
The ability to return null to be completely equivalent to returning
CompletableFuture.completedFuture(cb) would cover a common case
(synchronous consumption) without incurring in forced allocation.
Correct, but from API standpoint this would be worse. The act of
explicitly passing back the reference to CharBuffer is a conscious
transfer of ownership. Passing null is not and could be a source of bugs.
Regards, Peter