halkyon/packages/halkyon_app/test/support/eventually.dart
Tizian 「ティツィアーン」 39b43217f6
refactor(app): delayed deletions move into halkyon_app (ADR 0030, D24)
Learn's DelayedDeletions, unchanged, with its test, so that Train's
workouts can be deleted with an undo as Learn's items are. Learn's
deletions import it from halkyon_app now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-30 15:52:50 +01:00

17 lines
578 B
Dart

import 'package:flutter_test/flutter_test.dart';
/// Waits until [condition] holds, checking every few milliseconds, and fails
/// after [timeout]: for what follows a real timer, without betting on how
/// fast a busy machine runs.
Future<void> eventually(
bool Function() condition, {
Duration timeout = const Duration(seconds: 10),
}) async {
final stopwatch = Stopwatch()..start();
while (!condition()) {
if (stopwatch.elapsed > timeout) {
fail('Still not so after $timeout.');
}
await Future<void>.delayed(const Duration(milliseconds: 10));
}
}