in awsiot/eventstreamrpc.py [0:0]
def close(self, reason: Optional[Exception] = None) -> Future:
"""
Close the connection.
Shutdown is asynchronous. This call has no effect if the connection
is already closed or closing.
Args:
reason: If set, the connection will
close with this error as the reason (unless
it was already closing for another reason).
Returns:
The future which will complete
when the shutdown process is done. The future will have an
exception if shutdown was caused by an error, or a result
of None if the shutdown was clean and user-initiated.
"""
with self._synced as synced:
if synced.state == _ClientState.DISCONNECTED:
# do nothing, already disconnected
pass
elif synced.state == _ClientState.DISCONNECTING:
# do nothing, already disconnecting for some other reason
pass
else:
synced.close_reason = reason
synced.state = _ClientState.DISCONNECTING
# close connection if it exists.
# if it doesn't exist yet, then it's connecting right now
# and will get closed the moment it exists.
if synced.current_connection:
synced.current_connection.close()
return synced.closed_future