attachOneShot method

Object attachOneShot(
  1. Function listener
)

Attaches a function that will be executed when notify() is called. The listener is detached automatically on notify(), which invalidates the listener key after first invocation.

Returns a key object that can be used to detach the listener from the notifier to stop execution on notify() call and avoid memory leaks.

Implementation

Object attachOneShot(Function listener) {
  final key = attach(listener);
  _oneShotKeys.add(key);
  return key;
}