Skip to content

Commit 1eb1135

Browse files
authored
Migrate away from fake_time (#8782)
* Migrate away from fake_time * allow timer use * Added documentation comments
1 parent f384748 commit 1eb1135

File tree

13 files changed

+306
-635
lines changed

13 files changed

+306
-635
lines changed

app/lib/package/api_export/api_exporter.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:pub_dev/frontend/handlers/atom_feed.dart';
1313
import 'package:pub_dev/service/security_advisories/backend.dart';
1414
import 'package:pub_dev/shared/exceptions.dart';
1515
import 'package:pub_dev/shared/parallel_foreach.dart';
16+
import 'package:pub_dev/task/clock_control.dart';
1617

1718
import '../../search/backend.dart';
1819
import '../../shared/datastore.dart';
@@ -308,7 +309,8 @@ final class ApiExporter {
308309
seen.removeWhere((_, updated) => updated.isBefore(since));
309310

310311
// Wait until aborted or 10 minutes before scanning again!
311-
await abort.future.timeout(Duration(minutes: 10), onTimeout: () => null);
312+
await abort.future
313+
.timeoutWithClock(Duration(minutes: 10), onTimeout: () => null);
312314
}
313315
}
314316

app/lib/service/services.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ Future<R> _withPubServices<R>(FutureOr<R> Function() fn) async {
300300

301301
// Create a zone-local flag to indicate that services setup has been completed.
302302
return await fork(
303-
() => Zone.current.fork(zoneValues: {
303+
() async => Zone.current.fork(zoneValues: {
304304
_pubDevServicesInitializedKey: true,
305305
}).run(
306306
() async {

app/lib/task/backend.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import 'package:pub_dev/shared/versions.dart'
3636
acceptedRuntimeVersions;
3737
import 'package:pub_dev/shared/versions.dart' as shared_versions
3838
show runtimeVersion;
39+
import 'package:pub_dev/task/clock_control.dart';
3940
import 'package:pub_dev/task/cloudcompute/cloudcompute.dart';
4041
import 'package:pub_dev/task/global_lock.dart';
4142
import 'package:pub_dev/task/handlers.dart';
@@ -138,7 +139,7 @@ class TaskBackend {
138139
st,
139140
);
140141
// Sleep 5 minutes to reduce risk of degenerate behavior
141-
await Future.delayed(Duration(minutes: 5));
142+
await clock.delayed(Duration(minutes: 5));
142143
}
143144
}
144145
} catch (e, st) {
@@ -176,7 +177,7 @@ class TaskBackend {
176177
st,
177178
);
178179
// Sleep 5 minutes to reduce risk of degenerate behavior
179-
await Future.delayed(Duration(minutes: 5));
180+
await clock.delayed(Duration(minutes: 5));
180181
}
181182
}
182183
} catch (e, st) {
@@ -349,7 +350,8 @@ class TaskBackend {
349350
seen.removeWhere((_, updated) => updated.isBefore(since));
350351

351352
// Wait until aborted or 10 minutes before scanning again!
352-
await abort.future.timeout(Duration(minutes: 10), onTimeout: () => null);
353+
await abort.future
354+
.timeoutWithClock(Duration(minutes: 10), onTimeout: () => null);
353355
}
354356
}
355357

0 commit comments

Comments
 (0)