blocking static method

ObjCBlock<Void Function(Pointer<Void>, NSCoder)> blocking(
  1. void fn(
    1. Pointer<Void>,
    2. NSCoder
    ), {
  2. bool keepIsolateAlive = true,
})

Creates a blocking block from a Dart function.

This callback can be invoked from any native thread, and will block the caller until the callback is handled by the Dart isolate that created the block. Async functions are not supported.

If keepIsolateAlive is true, this block will keep this isolate alive until it is garbage collected by both Dart and ObjC. If the owner isolate has shut down, and the block is invoked by native code, it may block indefinitely, or have other undefined behavior.

Implementation

static objc.ObjCBlock<ffi.Void Function(ffi.Pointer<ffi.Void>, objc.NSCoder)> blocking(
  void Function(ffi.Pointer<ffi.Void>, objc.NSCoder) fn, {
  bool keepIsolateAlive = true,
}) {
  final raw = objc.newClosureBlock(
    _ObjCBlock_ffiVoid_ffiVoid_NSCoder_blockingCallable.nativeFunction.cast(),
    (ffi.Pointer<ffi.Void> arg0, ffi.Pointer<objc.ObjCObject> arg1) =>
        fn(arg0, objc.NSCoder.castFromPointer(arg1, retain: false, release: true)),
    keepIsolateAlive,
  );
  final rawListener = objc.newClosureBlock(
    _ObjCBlock_ffiVoid_ffiVoid_NSCoder_blockingListenerCallable.nativeFunction.cast(),
    (ffi.Pointer<ffi.Void> arg0, ffi.Pointer<objc.ObjCObject> arg1) =>
        fn(arg0, objc.NSCoder.castFromPointer(arg1, retain: false, release: true)),
    keepIsolateAlive,
  );
  final wrapper = _NativeLibrary_wrapBlockingBlock_18v1jvf(raw, rawListener, objc.objCContext);
  objc.objectRelease(raw.cast());
  objc.objectRelease(rawListener.cast());
  return objc.ObjCBlock<ffi.Void Function(ffi.Pointer<ffi.Void>, objc.NSCoder)>(
    wrapper,
    retain: false,
    release: true,
  );
}