Skip to content

Commit 68f6e3a

Browse files
committed
feat: implement abort functionality in query action processing
1 parent 7a54eb3 commit 68f6e3a

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

firestore/lib/utils/query.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:math';
66
import 'package:tekartik_common_utils/common_utils_import.dart';
77
import 'package:tekartik_firebase_firestore/firestore.dart';
88

9+
/// Returns -1 to abort (existing count, 0 or more is returned)
910
typedef TekartikFirestoreQueryActionFunction =
1011
Future<int> Function(List<String> ids);
1112

@@ -191,6 +192,11 @@ extension TekartikFirestoreQueryExt on Query {
191192
}).toList();
192193

193194
var processCount = await actionFunction(idsToProcess);
195+
// Return -1 to abort
196+
if (processCount < 0) {
197+
// Abort
198+
break;
199+
}
194200
count += processCount;
195201
if (maxRemainingCount != null) {
196202
maxRemainingCount -= processCount;

firestore_test/lib/utils_query_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,21 @@ void runUtilsQueryTest({
166166
),
167167
4,
168168
);
169+
// cancel
170+
query = collRef
171+
.where('text', isGreaterThanOrEqualTo: '07')
172+
.orderBy('text');
173+
expect(
174+
await query.queryAction(
175+
limit: 9,
176+
batchSize: 3,
177+
orderByFields: ['text'],
178+
actionFunction: (ids) async {
179+
return -1;
180+
},
181+
),
182+
0,
183+
);
169184
});
170185
});
171186
}

0 commit comments

Comments
 (0)