Skip to content

fix: async cache storing exception fixed #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated test cases
  • Loading branch information
akmalviya03 committed May 2, 2025
commit 880ebb898b1cf2d09d3bab58e011451eb1b23aa9
12 changes: 9 additions & 3 deletions pkgs/async/test/async_cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ void main() {

test('should not fetch when callback throws exception', () async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure "fetch" is the verb I'd use here (aka: I don't know what the description means).
It's consistent with the other tests. I also can't read those.

That's not really your issue to fix, though. (Should we say "recompute" instead of "fetch". Why is the method called fetch to begin with, seems to assume a specific use-case.)

Copy link
Author

@akmalviya03 akmalviya03 Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I also thought the same, to rename it to something more generic.

cache = AsyncCache(const Duration(hours: 1), cacheErrors: false);

Future<String> asyncFunctionThatThrows() {
throw Exception();
}

var errorThrowingFuture = cache.fetch(asyncFunctionThatThrows);
await expectLater(errorThrowingFuture, throwsA(isException));

var valueFuture = cache.fetch(() async => 'Success');
expect(await valueFuture, 'Success');
FakeAsync().run((fakeAsync) async {
var timesCalled = 0;
Future<String> call() async => 'Called ${++timesCalled}';

expect(await cache.fetch(call), 'Called 1');

fakeAsync.elapse(const Duration(hours: 1));
expect(await cache.fetch(call), 'Called 2');
});
});

test('should fetch via a callback when no cache exists', () async {
Expand Down