Skip to content

Commit

Permalink
Merge cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
liamappelbe committed Jan 7, 2025
1 parent ccd5d9e commit 4b250cd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 32 deletions.
3 changes: 1 addition & 2 deletions pkgs/ffigen/lib/src/code_generator/objc_protocol.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class ObjCProtocol extends NoLookUpBinding with ObjCMethods {
if (block.hasListener) {
listenerBuilders = '''
($funcType func) => $blockUtils.listener($wrapper),
($funcType func, Duration timeout) =>
$blockUtils.blocking($wrapper, timeout: timeout),
($funcType func) => $blockUtils.blocking($wrapper),
''';
maybeImplementAsListener = 'implementAsListener';
maybeImplementAsBlocking = 'implementAsBlocking';
Expand Down
22 changes: 0 additions & 22 deletions pkgs/ffigen/test/native_objc_test/protocol_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,28 +278,6 @@ void main() {
expect(await listenerCompleter.future, 123456);
});

test('Method implementation as blocking with timeout', () async {
final consumer = ProtocolConsumer.new1();

int value = 0;
final protocolBuilder = ObjCProtocolBuilder();
MyProtocol.voidMethod_.implementAsBlocking(
protocolBuilder,
(int x) {
waitSync(Duration(milliseconds: 300));
value = x;
},
timeout: Duration(milliseconds: 100),
);
final protocolImpl = protocolBuilder.build();

// Blocking method with timeout.
consumer.callMethodOnRandomThread_(protocolImpl);
expect(value, 0);
await Future.delayed(Duration(milliseconds: 1000));
expect(value, 123);
});

test('Multiple protocol implementation as blocking', () async {
final consumer = ProtocolConsumer.new1();

Expand Down
5 changes: 2 additions & 3 deletions pkgs/objective_c/lib/src/objective_c_bindings_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6417,11 +6417,10 @@ abstract final class NSStreamDelegate {
ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent.listener(
(ffi.Pointer<ffi.Void> _, NSStream arg1, NSStreamEvent arg2) =>
func(arg1, arg2)),
(void Function(NSStream, NSStreamEvent) func, Duration timeout) =>
(void Function(NSStream, NSStreamEvent) func) =>
ObjCBlock_ffiVoid_ffiVoid_NSStream_NSStreamEvent.blocking(
(ffi.Pointer<ffi.Void> _, NSStream arg1, NSStreamEvent arg2) =>
func(arg1, arg2),
timeout: timeout),
func(arg1, arg2)),
);
}

Expand Down
8 changes: 3 additions & 5 deletions pkgs/objective_c/lib/src/protocol_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ObjCProtocolMethod<T extends Function> {
class ObjCProtocolListenableMethod<T extends Function>
extends ObjCProtocolMethod<T> {
final ObjCBlockBase Function(T) _createListenerBlock;
final ObjCBlockBase Function(T, Duration) _createBlockingBlock;
final ObjCBlockBase Function(T) _createBlockingBlock;

/// Only for use by ffigen bindings.
ObjCProtocolListenableMethod(super._proto, super._sel, super._signature,
Expand All @@ -100,11 +100,9 @@ class ObjCProtocolListenableMethod<T extends 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 implemented
/// the method. Async functions are not supported.
void implementAsBlocking(ObjCProtocolBuilder builder, T? function,
{Duration timeout = const Duration(seconds: 3)}) {
void implementAsBlocking(ObjCProtocolBuilder builder, T? function) {
if (function != null) {
builder.implementMethod(
_sel, _sig, _createBlockingBlock(function, timeout));
builder.implementMethod(_sel, _sig, _createBlockingBlock(function));
}
}
}

0 comments on commit 4b250cd

Please sign in to comment.