getCallbackHandle method

CallbackHandle getCallbackHandle (Function callback)

Get a handle to a named top-level or static callback function which can be easily passed between isolates.

callback must not be null.

Returns a CallbackHandle that can be provided to PluginUtilities.getCallbackFromHandle to retrieve a tear-off of the original callback. If callback is not a top-level or static function, null is returned.

Implementation

static CallbackHandle getCallbackHandle(Function callback) {
  assert(callback != null, "'callback' must not be null.");
  return _forwardCache.putIfAbsent(callback, () {
    final int handle = _getCallbackHandle(callback);
    return handle != null ? new CallbackHandle.fromRawHandle(handle) : null;
  });
}