'Call the given callback when the stream is closed.
This is not necessary for applications that use the `.Future`
interface; all outstanding ``Futures`` will resolve with a
`StreamClosedError` when the stream is closed.'

def set_close_callback(self, callback):

    self._close_callback = stack_context.wrap(callback)
    self._maybe_add_error_listener()
