amaembo / streamex

Enhancing Java Stream API
Apache License 2.0
2.19k stars 251 forks source link

onClose #230

Closed maf123sp closed 4 years ago

maf123sp commented 4 years ago

Currently onCLose registers only a new closeHandler - any existing handler is removed.

Solution: a) accept any existing handler and install a local handler like closeHandler = () -> { newHandler.start(); existingHanlder.start(); } b) or implement a solution which allows to register and remove any number of closeHandlers like an event listeners

Thanks,

Matthias

amaembo commented 4 years ago

Could you please provide a complete code sample with expected behavior and actual behavior? Thanks.

maf123sp commented 4 years ago

Hello, the case can be closed. In my use case (issue) I used the onClose command to close a connected stream. My expectation was, that both stream are closed when the try() scope has left. Unfortunately, I saw, that in some circumstances the streams are still open. Definitely, the try() scope has left - but the close() statement of both statements has not proceeded. With some debugging code, I have monitored the flow. My final solution was the @Cleanup annotation of lombok. Now the streams are closed successfully. So far I don't understand, why the try() statement has not triggered an Autoclosable::close call or why this call was not successful. But my initial concern according to StreamEx was not correct.

Nevertheless thanks to the team for your answer and for the excellent work with StreamEx.

amaembo commented 4 years ago

Thank you for the detailed comment!