Skip to content

An open-source cross-platform alternative to AirDrop

fix: parallelize tasks

Tien Do Namd01481b1380a
diff --git a/common/lib/src/discovery/multicast_discovery.dart b/common/lib/src/discovery/multicast_discovery.dart
index 071b23bd..93168251 100644
--- a/common/lib/src/discovery/multicast_discovery.dart
+++ b/common/lib/src/discovery/multicast_discovery.dart
@@ -69,9 +69,7 @@ class MulticastService {
}
// Tell everyone in the network that I am online
- unawaited(
- sendAnnouncement(),
- );
+ sendAnnouncement(); // ignore: unawaited_futures
yield* streamController.stream;
}
diff --git a/common/lib/src/isolate/child/main.dart b/common/lib/src/isolate/child/main.dart
index 82197058..efb42e77 100644
--- a/common/lib/src/isolate/child/main.dart
+++ b/common/lib/src/isolate/child/main.dart
@@ -1,3 +1,5 @@
+import 'dart:async';
+
import 'package:common/src/isolate/child/sync_provider.dart';
import 'package:common/src/isolate/dto/send_to_isolate_data.dart';
import 'package:common/util/logger.dart';
@@ -47,18 +49,23 @@ Future<void> setupChildIsolateHelper<S, R>({
_logger.info('Child isolate is ready: $debugLabel (logLevel: ${initialData.logLevel})');
await for (final message in receiveFromMain) {
- final syncState = message.syncState;
- if (syncState != null) {
- isolateContainer.redux(syncProvider).dispatch(UpdateSyncStateAction(syncState));
- }
+ _handleMessage(debugLabel, message, handler);
+ }
+}
+
+// separate function to avoid blocking the for loop
+void _handleMessage<S>(String debugLabel, SendToIsolateData<S> message, Future<void> Function(S data) handler) async {
+ final syncState = message.syncState;
+ if (syncState != null) {
+ isolateContainer.redux(syncProvider).dispatch(UpdateSyncStateAction(syncState));
+ }
- final data = message.data;
- if (data != null) {
- try {
- await handler(data);
- } catch (e) {
- _logger.severe('Error in $debugLabel: $e', e);
- }
+ final data = message.data;
+ if (data != null) {
+ try {
+ await handler(data);
+ } catch (e) {
+ _logger.severe('Error in $debugLabel: $e', e);
}
}
}