WebSocket client API
Peter Levart
peter.levart at gmail.com
Wed Oct 21 13:13:15 UTC 2015
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
More information about the net-dev
mailing list