nextPart method

String nextPart(
  1. int timeoutMs
)

Pull the next transcription part (JSON string).

Throws AimuxTranscriptionEndedException when the stream finished normally, AimuxTranscriptionTimeoutException when no part arrived in time (retryable). timeoutMs: >0 wait at most; 0 immediate poll; negative = wait indefinitely.

Implementation

String nextPart(int timeoutMs) {
  _checkOpen();
  return withAimuxCError((err) {
    final ptr = _ffi.transcriptionNextPart(_handle, timeoutMs, err);
    if (ptr != nullptr) {
      try {
        return ptr.toDartString();
      } finally {
        aimuxFreeString(ptr);
      }
    }
    // NULL: disambiguate via err.code. Build the failure exception FIRST
    // (it reads the message), then free before the sentinel checks.
    final failure = err.ref.code == AimuxErrorCode.timeout ||
            err.ref.code == AimuxErrorCode.ok
        ? null
        : AimuxException.fromC(err.ref);
    _freeCError(err);
    if (err.ref.code == AimuxErrorCode.timeout) {
      throw AimuxTranscriptionTimeoutException();
    }
    if (err.ref.code == AimuxErrorCode.ok) {
      throw AimuxTranscriptionEndedException();
    }
    throw failure!;
  });
}