wait method

Future<JobStatus> wait({
  1. Duration pollInterval = const Duration(milliseconds: 10),
})

Implementation

Future<JobStatus> wait({
  Duration pollInterval = const Duration(milliseconds: 10),
}) async {
  if (pollInterval.isNegative) {
    throw ArgumentError.value(
      pollInterval,
      'pollInterval',
      'must be nonnegative',
    );
  }
  final lease = _begin();
  try {
    while (true) {
      if (_owner.closeRequested) {
        throw const StaleHandleException('Query job was abandoned');
      }
      final status = await _pollRaw(lease.handle);
      if (status.state == JobState.failed) {
        _owner.close();
        throw status.error ??
            ComputeException(status.message ?? 'Native query job failed');
      }
      if (status.state == JobState.cancelled) {
        _owner.close();
        throw status.error ??
            QueryCancelledException(
              status.message ?? 'Native query job was cancelled',
            );
      }
      if (status.terminal) return status;
      await Future<void>.delayed(pollInterval);
    }
  } catch (_) {
    _owner.close();
    rethrow;
  } finally {
    _end(lease);
  }
}