newCallbackWithHandle function

Callback<CbFuncWithHandle> newCallbackWithHandle()

Creates a new callback with a handle.

Returns a Callback instance with the specified function type.

Implementation

Callback<CbFuncWithHandle> newCallbackWithHandle() {
  final completer = Completer<AskarCallbackResult>();

  late final NativeCallable<CbFuncWithHandle> nativeCallable;

  void callback(int callbackId, int errorCode, int handle) {
    completer.complete(AskarCallbackResult(ErrorCode.fromInt(errorCode), true, handle));
    nativeCallable.close();
  }

  nativeCallable = NativeCallable<CbFuncWithHandle>.listener(callback);

  return Callback<CbFuncWithHandle>(nativeCallable, completer, nextCallbackId());
}