NativeCallable<T extends Function>.isolateLocal constructor

NativeCallable<T extends Function>.isolateLocal(
  1. @DartRepresentationOf("T") Function callback, {
  2. Object? exceptionalReturn,
})

Constructs a NativeCallable that must be invoked from the same thread that created it.

If an exception is thrown by the callback, the native function will return the exceptionalReturn, which must be assignable to the return type of the callback.

The returned function address can only be invoked on the mutator (main) thread of the current isolate. It will abort the process if invoked on any other thread. Use NativeCallable.listener to create callbacks that can be invoked from any thread.

Unlike Pointer.fromFunction, NativeCallables can be constructed from any Dart function or closure, not just static or top level functions.

This callback must be closed when it is no longer needed. The Isolate that created the callback will be kept alive until close is called. After NativeCallable.close is called, invoking the nativeFunction from native code will cause undefined behavior.

Implementation

factory NativeCallable.isolateLocal(
  @DartRepresentationOf("T") Function callback, {
  Object? exceptionalReturn,
}) {
  throw UnsupportedError("NativeCallable cannot be constructed dynamically.");
}