start method
Future<int>
start({
- required FutoSwipeBundle bundle,
- required List<
FutoSwipeWord> lexicon, - required bool includeModelVocabulary,
- required int beamWidth,
Returns the swipeable lexicon size.
Implementation
Future<int> start({
required FutoSwipeBundle bundle,
required List<FutoSwipeWord> lexicon,
required bool includeModelVocabulary,
required int beamWidth,
}) async {
if (_sendPort != null) {
throw StateError('FUTO Swipe isolate already started');
}
final handshake = ReceivePort();
try {
_isolate = await Isolate.spawn(
_entryPoint,
handshake.sendPort,
onError: handshake.sendPort,
debugName: 'fonnx-futo-swipe',
);
final first = await handshake.first;
if (first is! SendPort) {
throw Exception('Failed to start FUTO Swipe isolate: $first');
}
_sendPort = first;
return await _request<int>(
_Initialize(
bundle,
lexicon,
includeModelVocabulary,
beamWidth,
fonnxOrtDylibPathOverride,
),
);
} catch (_) {
_isolate?.kill();
_isolate = null;
_sendPort = null;
rethrow;
} finally {
handshake.close();
}
}