Subscription#
- class carb.Subscription#
Bases:
pybind11_object
Subscription holder.
This object is returned by different subscription functions. Subscription lifetime is associated with this object. You can it while you need subscribed callback to be called. Then you can explicitly make it equal to `None` or call `unsubscribe` method or `del` it to unsubscribe.
Quite common patter of usage is when you have a class which subscribes to various callbacks and you want to subscription to stay valid while class instance is alive.
class Foo: def __init__(self): events = carb.events.get_events_interface() stream = events.create_event_stream() self._event_sub = stream.subscribe_to_pop(0, self._on_event) def _on_event(self, e): print(f'event {e}')
>>> f = Foo() >>> # f receives some events >>> f._event_sub = None >>> f = None
Methods
__init__
(self, arg0)unsubscribe
(self)- __init__(
- self: carb._carb.Subscription,
- arg0: Callable[[], None],
- unsubscribe(self: carb._carb.Subscription) None #