withIntCallback function

Future<int> withIntCallback(
  1. dynamic func(
    1. Pointer<NativeFunction<Void Function(Int32)>>
    )
)

Implementation

Future<int> withIntCallback(
    Function(Pointer<NativeFunction<Void Function(Int32)>>) func) async {
  JSArray retVal = createBoolCallback();
  var promise = retVal.toDart[0] as JSPromise<JSNumber>;

  var fnPtrAddress = retVal.toDart[1] as JSNumber;
  var fnPtr = Pointer<NativeFunction<Void Function(Int32)>>.fromAddress(
      fnPtrAddress.toDartInt);
  func(fnPtr);
  final addr = await promise.toDart;
  return addr.toDartInt;
}