initialize method
Initializes the native LiteRT-LM engine.
Implementation
Future<void> initialize() async {
if (_state == _EngineState.initialized) {
throw const LiteRtLmException('Engine is already initialized.');
}
if (_state == _EngineState.failed) {
throw const LiteRtLmException('Engine failed and must be disposed.');
}
if (_state == _EngineState.disposed) {
throw const LiteRtLmException('Engine is already disposed.');
}
try {
await LiteRtLmNativeRuntime.instance.initializeEngine(_handle);
_state = _EngineState.initialized;
} catch (_) {
_state = _EngineState.failed;
rethrow;
}
}