If sender is a device you program too, you can set it to send a "endMessage" message. This way, when you receive the "endMessage" you can safely destroy the service (after of course having processed your data). If you cannot send an "endMessage" you can initialize a timer and set it enabled inside the aStreams_newData sub. If a certain duration passes, this will mean that we don't receive new data for this period. This way, you can proceed with processing the received data and so on.
Finally, you can use the aStreams_terminated event, if it fires when your device is closing the communication (if it's closing it).