Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Revert accidentally commited change
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Sep 26, 2023
1 parent 8558f74 commit 989f7fe
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/ouisync_plugin.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:ffi';
import 'dart:isolate';

Expand Down Expand Up @@ -839,22 +838,26 @@ T _withPoolSync<T>(T Function(_Pool) fun) {
}

// Helper to invoke a native async function.
Future<void> _invoke(void Function(int) fun) async {
Future<T> _invoke<T>(void Function(int) fun) async {
final recvPort = ReceivePort();

try {
fun(recvPort.sendPort.nativePort);

var buffer = await recvPort.first as Uint8List;

if (buffer.isEmpty) {
return;
ErrorCode? code;

// Is there a better way to retrieve the first two values of a stream?
await for (var item in recvPort) {
if (code == null) {
code = ErrorCode.decode(item as int);
} else if (code == ErrorCode.ok) {
return item as T;
} else {
throw Error(code, item as String);
}
}

final code = ErrorCode.decode(buffer.buffer.asByteData().getUint16(0));
final message = utf8.decode(buffer.sublist(2));

throw Error(code, message);
throw Exception('invoked native async function did not produce any result');
} finally {
recvPort.close();
}
Expand Down

0 comments on commit 989f7fe

Please sign in to comment.