Commit 13bd0ea3 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added the ability to give directly a callable object to the on_disconnect callback.

parent f9c01b08
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -320,22 +320,32 @@ class RpcConnection(object):
        else:
            pass # Malformed messages are note processed
    
    def shutdown(self, callback_name=None):
    def shutdown(self, callback=None):
        '''
        Shutdown this connection.
        
        :param callback_name: Name of the callback to call on the handler
        :type callback_name: :class:`str` or None
        :param callback: Name of the callback to call on the handler or a
            callable to call when the connection is shutdown.
        :type callback: :class:`str` or callable or None
        '''

        self._sock.close()
        if callback_name is not None and self._handler is not None:

        if callback is not None and not callable(callback):
            if self._handler is not None:
                try:
                func = self._handler[callback_name]
                    callback = self._handler[callback]
                except KeyError:
                pass
                    callback = None
            else:
                func(self)
                callback = None

        if callback is not None:
            try:
                callback(self)
            except Exception as err:
                logging.error('Error while execution of shutdown '
                              'callback: %s' % err)

    def clean_call(self, msg_id):
        '''