pullServer method

Future<void> pullServer(
  1. PullInfoDto pullInfo, {
  2. required void onStart(
    1. PullStartDto pullStart
    ),
  3. required void onDownload(
    1. PullDownloadDto pullDownload
    ),
  4. required void onDone(
    1. PullDoneDto result
    ),
  5. required void onPullError(
    1. PullErrorDto error
    ),
  6. void onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

POST /servers/pull

Implementation

Future<void> pullServer(
  PullInfoDto pullInfo, {
  required void Function(PullStartDto pullStart) onStart,
  required void Function(PullDownloadDto pullDownload) onDownload,
  required void Function(PullDoneDto result) onDone,
  required void Function(PullErrorDto error) onPullError,
  void Function(Object error, StackTrace stackTrace)? onError,
}) async {
  try {
    await for (final event in pullServerEvents(pullInfo)) {
      switch (event) {
        case PullStarted(:final data):
          onStart(data);
        case PullProgress(:final data):
          onDownload(data);
        case PullCompleted(:final data):
          onDone(data);
        case PullFailed(:final data):
          onPullError(data);
      }
    }
  } catch (error, stackTrace) {
    final normalized = _normalizeError(error);
    if (onError != null) {
      onError(normalized, stackTrace);
      return;
    }
    if (identical(normalized, error)) rethrow;
    Error.throwWithStackTrace(normalized, stackTrace);
  }
}