withCameraWhenAvailableSync<T> static method

Future<T?> withCameraWhenAvailableSync<T>(
  1. CameraPosition position,
  2. CameraOwner owner,
  3. T operation(
    1. Camera camera
    ), [
  4. int? timeoutMs,
])

Execute camera operations, waiting for ownership if necessary (synchronous version)

Implementation

static Future<T?> withCameraWhenAvailableSync<T>(
  CameraPosition position,
  CameraOwner owner,
  T Function(Camera camera) operation, [
  int? timeoutMs,
]) async {
  // Try to get ownership, wait if necessary
  final acquired = await requestOwnership(position, owner, timeoutMs);
  if (!acquired) {
    SdkLogger.info('CameraOwnershipHelper', 'withCameraWhenAvailableSync',
        'Could not acquire camera ownership for ${owner.id} within timeout');
    return null;
  }

  final camera = Camera.atPosition(position);
  if (camera == null) {
    SdkLogger.info(
        'CameraOwnershipHelper', 'withCameraWhenAvailableSync', 'Camera not available at position $position');
    return null;
  }

  try {
    final result = operation(camera);
    return result;
  } catch (error) {
    SdkLogger.info(
        'CameraOwnershipHelper', 'withCameraWhenAvailableSync', 'Camera operation failed for ${owner.id}: $error');
    rethrow;
  }
}