Skip to content

Commit

Permalink
fix check-urls
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Nov 23, 2021
1 parent ebe4296 commit d2490c5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/check-urls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
- name: Run check_urls/main.dart
run: dart run main.dart

- name: Run example/lib/rxdart_ext_example.dart
run: dart run example/lib/rxdart_ext_example.dart

run-example:
runs-on: ubuntu-latest
defaults:
Expand Down
16 changes: 15 additions & 1 deletion check_urls/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,24 @@ Future<bool> testUrl(Uri url) async {
return success;
}

Future<bool> testUrlWithRetry(Uri url) async {
var retryCount = 0;
while (true) {
final success = await testUrl(url);
if (success) {
return true;
}
if (retryCount++ >= 3) {
return false;
}
}
}

Future<List<Uri>> test(Iterable<String> urls) {
return Stream.fromIterable(urls)
.map(Uri.parse)
.asyncMap((url) => testUrl(url).then((success) => success ? null : url))
.asyncMap((url) =>
testUrlWithRetry(url).then((success) => success ? null : url))
.where((url) => url != null)
.cast<Uri>()
.toList();
Expand Down

0 comments on commit d2490c5

Please sign in to comment.