mirror of
https://github.com/immich-app/immich.git
synced 2025-05-24 01:12:58 -04:00
* feat(mobile): assets + exif stream sync placeholder * feat(mobile): assets + exif stream sync placeholder * refactor * fix: test * fix:test * refactor(mobile): sync stream service (#17687) * refactor: sync stream to use callbacks * pr feedback * pr feedback * pr feedback * fix: test --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com> --------- Co-authored-by: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
40 lines
886 B
Dart
40 lines
886 B
Dart
// ignore_for_file: avoid-passing-async-when-sync-expected
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:immich_mobile/providers/infrastructure/sync_stream.provider.dart';
|
|
import 'package:immich_mobile/utils/isolate.dart';
|
|
import 'package:worker_manager/worker_manager.dart';
|
|
|
|
class BackgroundSyncManager {
|
|
Cancelable<void>? _syncTask;
|
|
|
|
BackgroundSyncManager();
|
|
|
|
Future<void> cancel() {
|
|
final futures = <Future>[];
|
|
|
|
if (_syncTask != null) {
|
|
futures.add(_syncTask!.future);
|
|
}
|
|
_syncTask?.cancel();
|
|
_syncTask = null;
|
|
|
|
return Future.wait(futures);
|
|
}
|
|
|
|
Future<void> sync() {
|
|
if (_syncTask != null) {
|
|
return _syncTask!.future;
|
|
}
|
|
|
|
_syncTask = runInIsolateGentle(
|
|
computation: (ref) => ref.read(syncStreamServiceProvider).sync(),
|
|
);
|
|
_syncTask!.whenComplete(() {
|
|
_syncTask = null;
|
|
});
|
|
return _syncTask!.future;
|
|
}
|
|
}
|