runOnceAsync method

Future<List<OrtValue?>> runOnceAsync(
  1. OrtRunOptions runOptions,
  2. Map<String, OrtValue> inputs, [
  3. List<String>? outputNames
])

Creates a new isolate for a single inference run. Each call creates a fresh isolate, allowing concurrent inference. The isolate is automatically killed after the inference completes. Useful for parallel inference or one-off async operations. Default timeout is 5 seconds. Use runOnceAsyncWithTimeout() for custom timeout.

Implementation

Future<List<OrtValue?>> runOnceAsync(
    OrtRunOptions runOptions, Map<String, OrtValue> inputs,
    [List<String>? outputNames]) async {
  // Create a new isolate session for this specific run
  // This allows multiple concurrent inferences
  final isolateSession = OrtIsolateSession(this);
  _activeIsolateSessions.add(isolateSession);

  try {
    final result = await isolateSession.run(runOptions, inputs, outputNames);
    return result;
  } finally {
    // Always clean up the isolate after use
    await isolateSession.release();
    _activeIsolateSessions.remove(isolateSession);
  }
}