run GomuksStart on an isolate
This commit is contained in:
parent
36f61a62d8
commit
f082a75d9c
1 changed files with 10 additions and 1 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import "dart:async";
|
import "dart:async";
|
||||||
import "dart:ffi";
|
import "dart:ffi";
|
||||||
|
import "dart:isolate";
|
||||||
|
|
||||||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
import "package:flutter/foundation.dart";
|
import "package:flutter/foundation.dart";
|
||||||
|
|
@ -112,12 +113,20 @@ class GomuksListenerController extends AsyncNotifier<void> {
|
||||||
|
|
||||||
ref.onDispose(callable.close);
|
ref.onDispose(callable.close);
|
||||||
|
|
||||||
final errorCode = GomuksStart(handle, callable.nativeFunction);
|
final errorCode = await _start(handle, callable.nativeFunction);
|
||||||
if (errorCode != 0) {
|
if (errorCode != 0) {
|
||||||
throw Exception("GomuksStart returned error code $errorCode");
|
throw Exception("GomuksStart returned error code $errorCode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<int> _start(
|
||||||
|
int handle,
|
||||||
|
Pointer<
|
||||||
|
NativeFunction<Void Function(Pointer<Char>, Int64, GomuksOwnedBuffer)>
|
||||||
|
>
|
||||||
|
callback,
|
||||||
|
) => Isolate.run(() => GomuksStart(handle, callback));
|
||||||
|
|
||||||
static final provider = AsyncNotifierProvider<GomuksListenerController, void>(
|
static final provider = AsyncNotifierProvider<GomuksListenerController, void>(
|
||||||
GomuksListenerController.new,
|
GomuksListenerController.new,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue