Skip to content

Commit 43760f9

Browse files
authored
Wrapped methods return a Future instead of executing right away (#1476)
1 parent f9d18f3 commit 43760f9

9 files changed

+67
-103
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- Wrapped methods return a `Future` instead of executing right away ([#1476](https://github.com/getsentry/sentry-dart/pull/1476))
8+
- Relates to ([#1462](https://github.com/getsentry/sentry-dart/pull/1462))
9+
510
### Dependencies
611

712
- Bump Android SDK from v6.19.0 to v6.19.1 ([#1466](https://github.com/getsentry/sentry-dart/pull/1466))

flutter/lib/src/sentry_asset_bundle.dart

+10-20
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class SentryAssetBundle implements AssetBundle {
5454

5555
@override
5656
Future<ByteData> load(String key) {
57-
Future<ByteData> future() async {
57+
return Future<ByteData>(() async {
5858
final span = _hub.getSpan()?.startChild(
5959
'file.read',
6060
description: 'AssetBundle.load: ${_fileName(key)}',
@@ -75,9 +75,7 @@ class SentryAssetBundle implements AssetBundle {
7575
await span?.finish();
7676
}
7777
return data;
78-
}
79-
80-
return future();
78+
});
8179
}
8280

8381
@override
@@ -90,7 +88,7 @@ class SentryAssetBundle implements AssetBundle {
9088

9189
Future<T> _loadStructuredDataWithTracing<T>(
9290
String key, _StringParser<T> parser) {
93-
Future<T> future() async {
91+
return Future<T>(() async {
9492
final span = _hub.getSpan()?.startChild(
9593
'file.read',
9694
description:
@@ -127,14 +125,12 @@ class SentryAssetBundle implements AssetBundle {
127125
await span?.finish();
128126
}
129127
return data;
130-
}
131-
132-
return future();
128+
});
133129
}
134130

135131
Future<T> _loadStructuredBinaryDataWithTracing<T>(
136132
String key, _ByteParser<T> parser) {
137-
Future<T> future() async {
133+
return Future<T>(() async {
138134
final span = _hub.getSpan()?.startChild(
139135
'file.read',
140136
description:
@@ -171,14 +167,12 @@ class SentryAssetBundle implements AssetBundle {
171167
await span?.finish();
172168
}
173169
return data;
174-
}
175-
176-
return future();
170+
});
177171
}
178172

179173
@override
180174
Future<String> loadString(String key, {bool cache = true}) {
181-
Future<String> future() async {
175+
return Future<String>(() async {
182176
final span = _hub.getSpan()?.startChild(
183177
'file.read',
184178
description: 'AssetBundle.loadString: ${_fileName(key)}',
@@ -199,9 +193,7 @@ class SentryAssetBundle implements AssetBundle {
199193
await span?.finish();
200194
}
201195
return data;
202-
}
203-
204-
return future();
196+
});
205197
}
206198

207199
void _setDataLength(dynamic data, ISentrySpan? span) {
@@ -238,7 +230,7 @@ class SentryAssetBundle implements AssetBundle {
238230
// This is an override on Flutter greater than 3.1
239231
// ignore: override_on_non_overriding_member
240232
Future<ImmutableBuffer> loadBuffer(String key) {
241-
Future<ImmutableBuffer> future() async {
233+
return Future<ImmutableBuffer>(() async {
242234
final span = _hub.getSpan()?.startChild(
243235
'file.read',
244236
description: 'AssetBundle.loadBuffer: ${_fileName(key)}',
@@ -259,9 +251,7 @@ class SentryAssetBundle implements AssetBundle {
259251
await span?.finish();
260252
}
261253
return data;
262-
}
263-
264-
return future();
254+
});
265255
}
266256

267257
Future<ImmutableBuffer> _loadBuffer(String key) {

sqflite/lib/src/sentry_batch.dart

+4-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SentryBatch implements Batch {
4040

4141
@override
4242
Future<List<Object?>> apply({bool? noResult, bool? continueOnError}) {
43-
Future<List<Object?>> future() async {
43+
return Future<List<Object?>>(() async {
4444
final currentSpan = _hub.getSpan();
4545

4646
final span = currentSpan?.startChild(
@@ -65,9 +65,7 @@ class SentryBatch implements Batch {
6565
} finally {
6666
await span?.finish();
6767
}
68-
}
69-
70-
return future();
68+
});
7169
}
7270

7371
@override
@@ -76,7 +74,7 @@ class SentryBatch implements Batch {
7674
bool? noResult,
7775
bool? continueOnError,
7876
}) {
79-
Future<List<Object?>> future() async {
77+
return Future<List<Object?>>(() async {
8078
final currentSpan = _hub.getSpan();
8179

8280
final span = currentSpan?.startChild(
@@ -102,9 +100,7 @@ class SentryBatch implements Batch {
102100
} finally {
103101
await span?.finish();
104102
}
105-
}
106-
107-
return future();
103+
});
108104
}
109105

110106
@override

sqflite/lib/src/sentry_database.dart

+4-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
5454

5555
@override
5656
Future<void> close() {
57-
Future<void> future() async {
57+
return Future<void>(() async {
5858
final currentSpan = _hub.getSpan();
5959
final span = currentSpan?.startChild(
6060
dbOp,
@@ -73,9 +73,7 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
7373
} finally {
7474
await span?.finish();
7575
}
76-
}
77-
78-
return future();
76+
});
7977
}
8078

8179
@override
@@ -105,7 +103,7 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
105103
Future<T> Function(Transaction txn) action, {
106104
bool? exclusive,
107105
}) {
108-
Future<T> future() async {
106+
return Future<T>(() async {
109107
final currentSpan = _hub.getSpan();
110108
final span = currentSpan?.startChild(
111109
_dbSqlOp,
@@ -136,8 +134,6 @@ class SentryDatabase extends SentryDatabaseExecutor implements Database {
136134
} finally {
137135
await span?.finish();
138136
}
139-
}
140-
141-
return future();
137+
});
142138
}
143139
}

sqflite/lib/src/sentry_database_executor.dart

+22-44
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
3131

3232
@override
3333
Future<int> delete(String table, {String? where, List<Object?>? whereArgs}) {
34-
Future<int> future() async {
34+
return Future<int>(() async {
3535
final currentSpan = _parentSpan ?? _hub.getSpan();
3636
final builder =
3737
SqlBuilder.delete(table, where: where, whereArgs: whereArgs);
@@ -55,14 +55,12 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
5555
} finally {
5656
await span?.finish();
5757
}
58-
}
59-
60-
return future();
58+
});
6159
}
6260

6361
@override
6462
Future<void> execute(String sql, [List<Object?>? arguments]) {
65-
Future<void> future() async {
63+
return Future<void>(() async {
6664
final currentSpan = _parentSpan ?? _hub.getSpan();
6765
final span = currentSpan?.startChild(
6866
SentryDatabase.dbSqlExecuteOp,
@@ -81,9 +79,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
8179
} finally {
8280
await span?.finish();
8381
}
84-
}
85-
86-
return future();
82+
});
8783
}
8884

8985
@override
@@ -93,7 +89,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
9389
String? nullColumnHack,
9490
ConflictAlgorithm? conflictAlgorithm,
9591
}) {
96-
Future<int> future() async {
92+
return Future<int>(() async {
9793
final currentSpan = _parentSpan ?? _hub.getSpan();
9894
final builder = SqlBuilder.insert(
9995
table,
@@ -125,9 +121,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
125121
} finally {
126122
await span?.finish();
127123
}
128-
}
129-
130-
return future();
124+
});
131125
}
132126

133127
@override
@@ -143,7 +137,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
143137
int? limit,
144138
int? offset,
145139
}) {
146-
Future<List<Map<String, Object?>>> future() async {
140+
return Future<List<Map<String, Object?>>>(() async {
147141
final currentSpan = _parentSpan ?? _hub.getSpan();
148142
final builder = SqlBuilder.query(
149143
table,
@@ -187,9 +181,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
187181
} finally {
188182
await span?.finish();
189183
}
190-
}
191-
192-
return future();
184+
});
193185
}
194186

195187
@override
@@ -206,7 +198,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
206198
int? offset,
207199
int? bufferSize,
208200
}) {
209-
Future<QueryCursor> future() async {
201+
return Future<QueryCursor>(() async {
210202
final currentSpan = _parentSpan ?? _hub.getSpan();
211203
final builder = SqlBuilder.query(
212204
table,
@@ -251,14 +243,12 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
251243
} finally {
252244
await span?.finish();
253245
}
254-
}
255-
256-
return future();
246+
});
257247
}
258248

259249
@override
260250
Future<int> rawDelete(String sql, [List<Object?>? arguments]) {
261-
Future<int> future() async {
251+
return Future<int>(() async {
262252
final currentSpan = _parentSpan ?? _hub.getSpan();
263253
final span = currentSpan?.startChild(
264254
SentryDatabase.dbSqlExecuteOp,
@@ -279,14 +269,12 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
279269
} finally {
280270
await span?.finish();
281271
}
282-
}
283-
284-
return future();
272+
});
285273
}
286274

287275
@override
288276
Future<int> rawInsert(String sql, [List<Object?>? arguments]) {
289-
Future<int> future() async {
277+
return Future<int>(() async {
290278
final currentSpan = _parentSpan ?? _hub.getSpan();
291279
final span = currentSpan?.startChild(
292280
SentryDatabase.dbSqlExecuteOp,
@@ -307,17 +295,15 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
307295
} finally {
308296
await span?.finish();
309297
}
310-
}
311-
312-
return future();
298+
});
313299
}
314300

315301
@override
316302
Future<List<Map<String, Object?>>> rawQuery(
317303
String sql, [
318304
List<Object?>? arguments,
319305
]) {
320-
Future<List<Map<String, Object?>>> future() async {
306+
return Future<List<Map<String, Object?>>>(() async {
321307
final currentSpan = _parentSpan ?? _hub.getSpan();
322308
final span = currentSpan?.startChild(
323309
SentryDatabase.dbSqlQueryOp,
@@ -338,9 +324,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
338324
} finally {
339325
await span?.finish();
340326
}
341-
}
342-
343-
return future();
327+
});
344328
}
345329

346330
@override
@@ -349,7 +333,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
349333
List<Object?>? arguments, {
350334
int? bufferSize,
351335
}) {
352-
Future<QueryCursor> future() async {
336+
return Future<QueryCursor>(() async {
353337
final currentSpan = _parentSpan ?? _hub.getSpan();
354338
final span = currentSpan?.startChild(
355339
SentryDatabase.dbSqlQueryOp,
@@ -374,14 +358,12 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
374358
} finally {
375359
await span?.finish();
376360
}
377-
}
378-
379-
return future();
361+
});
380362
}
381363

382364
@override
383365
Future<int> rawUpdate(String sql, [List<Object?>? arguments]) {
384-
Future<int> future() async {
366+
return Future<int>(() async {
385367
final currentSpan = _parentSpan ?? _hub.getSpan();
386368
final span = currentSpan?.startChild(
387369
SentryDatabase.dbSqlExecuteOp,
@@ -402,9 +384,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
402384
} finally {
403385
await span?.finish();
404386
}
405-
}
406-
407-
return future();
387+
});
408388
}
409389

410390
@override
@@ -415,7 +395,7 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
415395
List<Object?>? whereArgs,
416396
ConflictAlgorithm? conflictAlgorithm,
417397
}) {
418-
Future<int> future() async {
398+
return Future<int>(() async {
419399
final currentSpan = _parentSpan ?? _hub.getSpan();
420400
final builder = SqlBuilder.update(
421401
table,
@@ -449,8 +429,6 @@ class SentryDatabaseExecutor implements DatabaseExecutor {
449429
} finally {
450430
await span?.finish();
451431
}
452-
}
453-
454-
return future();
432+
});
455433
}
456434
}

0 commit comments

Comments
 (0)