pullServer method
Future<void>
pullServer(
- PullInfoDto pullInfo, {
- required void onStart(
- PullStartDto pullStart
- required void onDownload(
- PullDownloadDto pullDownload
- required void onDone(
- PullInfoDto pullInfo
- void onError(
- Object error,
- StackTrace stackTrace
POST /servers/pull?name=<target_name>&tag=<target_tag>
Implementation
Future<void> pullServer(
PullInfoDto pullInfo, {
required void Function(PullStartDto pullStart) onStart,
required void Function(PullDownloadDto pullDownload) onDownload,
required void Function(PullInfoDto pullInfo) onDone,
void Function(Object error, StackTrace stackTrace)? onError,
}) async {
try {
Stream<String> sseStream = await serverSse.request(
'/pull',
queryParameters: pullInfo.toJson(),
);
void Function(String event, Map<String, dynamic> data) onEvent =
(String event, Map<String, dynamic> data) {
if (event == EventType.START) {
onStart(PullStartDto.fromJson(data));
} else if (event == EventType.DATA) {
onDownload(PullDownloadDto.fromJson(data));
} else if (event == EventType.DONE) {
onDone(PullInfoDto.fromJson(data));
}
};
sseStream.listen(
(data) => SseClient.parse(data, onEvent),
onError: (error, stackTrace) {
onError?.call(error, stackTrace);
},
cancelOnError: true,
);
} catch (error, stackTrace) {
if (onError != null) {
onError(error, stackTrace);
return;
}
rethrow;
}
}