CallbackHandler<CallbackInputType, CallbackReturnType> class

Implementation of ICallbackHandler for managing callbacks with generic types.

This class provides a high-performance callback management system using FastMap for O(1) registration and removal operations.

Type parameters:

  • CallbackInputType - The input parameter type accepted by callbacks
  • CallbackReturnType - The return type produced by callbacks

Example:

final handler = CallbackHandler<String, int>();
handler.register((input) => input.length);
final results = handler.call('Hello');
print(results); // {callback_hashCode: 5}

Performance characteristics:

  • Register: O(1) amortized
  • Unregister: O(1)
  • Invoke/Call: O(n) where n is the number of registered callbacks
  • Clear: O(n)
Implemented types

Constructors

CallbackHandler()
Creates a new CallbackHandler instance.

Properties

hashCode int
The hash code for this object.
no setterinherited
map FastMap<int, CallbackWithReturn<CallbackInputType, CallbackReturnType>>
Internal storage for registered callbacks.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(CallbackInputType input) Map<int, CallbackReturnType>
Make the handler callable as a function
override
clear() → void
Clear all registered callbacks
override
invoke(CallbackInputType input) Map<int, CallbackReturnType>
Invoke all registered callbacks with the given input (deprecated).
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register(CallbackWithReturn<CallbackInputType, CallbackReturnType> callback) → void
Register a callback
override
toString() String
A string representation of this object.
inherited
unregister(CallbackWithReturn<CallbackInputType, CallbackReturnType> callback) → void
Unregister a callback
override

Operators

operator ==(Object other) bool
The equality operator.
inherited