Browse Source

make callback dict in EventEmitter private

pull/18/merge
Rossen Georgiev 9 years ago
parent
commit
4e886fa0d8
  1. 39
      steam/util/events.py

39
steam/util/events.py

@ -25,20 +25,21 @@ class EventEmitter(object):
gevent.idle()
if hasattr(self, '_event_callbacks'):
for callback in list(self._event_callbacks[event]):
if isinstance(callback, AsyncResult):
self.remove_listener(event, callback)
if hasattr(self, '_EventEmitter__callbacks'):
if event in self.__callbacks:
for callback in list(self.__callbacks[event]):
if isinstance(callback, AsyncResult):
self.remove_listener(event, callback)
result = args
if len(args) == 1:
result = args[0]
result = args
if len(args) == 1:
result = args[0]
callback.set(result)
else:
gevent.spawn(callback, *args)
callback.set(result)
else:
gevent.spawn(callback, *args)
gevent.idle()
gevent.idle()
# every event is also emitted as None
if event is not None:
@ -53,10 +54,14 @@ class EventEmitter(object):
:type callback: function, method or :py:class:`gevent.event.AsyncResult`
"""
if not hasattr(self, '_event_callbacks'):
if not hasattr(self, '_EventEmitter__callbacks'):
return
self._event_callbacks[event].pop(callback, None)
if event in self.__callbacks:
del self.__callbacks[event][callback]
if not self.__callbacks[event]:
del self.__callbacks[event]
def wait_event(self, event, timeout=None):
"""
@ -93,16 +98,16 @@ class EventEmitter(object):
To listen for any event, use :py:class:`None` as event identifier.
"""
if not hasattr(self, '_event_callbacks'):
self._event_callbacks = defaultdict(dict)
if not hasattr(self, '_EventEmitter__callbacks'):
self.__callbacks = defaultdict(dict)
# when used function
if callback:
self._event_callbacks[event][callback] = None
self.__callbacks[event][callback] = None
return
# as decorator
def wrapper(callback):
self._event_callbacks[event][callback] = None
self.__callbacks[event][callback] = None
return callback
return wrapper

Loading…
Cancel
Save