blocking static method
ObjCBlock<Void Function(NSObject, NSObject)>
blocking(
- void fn(
- Dartsec_protocol_options_t options,
- Dartsec_identity_t identity
- 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(objc.NSObject, objc.NSObject)>
blocking(
void Function(Dartdispatch_data_t, Dartdispatch_data_t) fn, {
bool keepIsolateAlive = true,
}) {
final raw = objc.newClosureBlock(
_ObjCBlock_ffiVoid_dispatchdatat_dispatchdatat_blockingCallable
.nativeFunction
.cast(),
(dispatch_data_t arg0, dispatch_data_t arg1) => fn(
objc.NSObject.castFromPointer(arg0, retain: false, release: true),
objc.NSObject.castFromPointer(arg1, retain: false, release: true),
),
keepIsolateAlive,
);
final rawListener = objc.newClosureBlock(
_ObjCBlock_ffiVoid_dispatchdatat_dispatchdatat_blockingListenerCallable
.nativeFunction
.cast(),
(dispatch_data_t arg0, dispatch_data_t arg1) => fn(
objc.NSObject.castFromPointer(arg0, retain: false, release: true),
objc.NSObject.castFromPointer(arg1, retain: false, release: true),
),
keepIsolateAlive,
);
final wrapper = _NativeBindingBindings_wrapBlockingBlock_pfv6jd(
raw,
rawListener,
objc.objCContext,
);
objc.objectRelease(raw.cast());
objc.objectRelease(rawListener.cast());
return objc.ObjCBlock<ffi.Void Function(objc.NSObject, objc.NSObject)>(
wrapper,
retain: false,
release: true,
);
}