add method

void Function() add(
  1. TCallback<T1> callback, {
  2. dynamic callbackKey,
})

Adds a new callback.

  • callback Specify the callback to add.
  • callbackKey Specify a key for the callback that can be used to identify the callback. If not specified, the callback itself will be used as the key.

Returns a function that removes the callback.

Implementation

void Function() add(TCallback<T1> callback, {dynamic callbackKey}) {
  if (this._queue.isNotEmpty) {
    Here().debugLogAlert(
      'Do not add callbacks while callbacks are executing. Call wait() first.',
    );
  }
  final k = callbackKey ?? callback;
  this._callbacks[k] = callback;
  return () => this._callbacks.remove(k);
}