handle<E extends T> method
HandlerCanceler
handle<E extends T>(
- EventHandler<
E> handler
inherited
handle events of type E
with handler
returns a HandlerCanceler
that can be used to cancel the handler and clear it from the memory
also any handler will be canceled and cleared if the emitter is destroyed by calling dispose
or if clearHandlers
is called
Implementation
HandlerCanceler handle<E extends T>(EventHandler<E> handler) {
final _sub = filteredStream<E>().listen(handler);
_subscriptions.add(_sub);
bool isCanceled = false;
return () async {
if (isCanceled) return;
_subscriptions.remove(_sub);
isCanceled = true;
await _sub.cancel();
};
}