Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Fix places awaiting void, for dart 2. #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 9 additions & 7 deletions lib/src/async_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ class AsyncCache<T> {
/// Fires when the cache should be considered stale.
Timer _stale;

/// Creates a cache that invalidates after an in-flight request is complete.
///
/// An ephemeral cache guarantees that a callback function will only be
/// executed at most once concurrently. This is useful for requests for which
/// data is updated frequently but stale data is acceptable.
factory AsyncCache.ephemeral() => new AsyncCache(Duration.zero);

/// Creates a cache that invalidates its contents after [duration] has passed.
///
/// The [duration] starts counting after the Future returned by [fetch]
/// completes, or after the Stream returned by [fetchStream] emits a done
/// event.
AsyncCache(this._duration);

/// Creates a cache that invalidates after an in-flight request is complete.
///
/// An ephemeral cache guarantees that a callback function will only be
/// executed at most once concurrently. This is useful for requests for which
/// data is updated frequently but stale data is acceptable.
factory AsyncCache.ephemeral() => new AsyncCache(Duration.zero);

/// Returns a cached value from a previous call to [fetch], or runs [callback]
/// to compute a new one.
///
Expand Down Expand Up @@ -90,7 +90,9 @@ class AsyncCache<T> {

/// Removes any cached value.
void invalidate() {
// TODO: This does not return a future, but probably should.
_cachedValueFuture = null;
// TODO: This does not await, but probably should.
_cachedStreamSplitter?.close();
_cachedStreamSplitter = null;
_stale?.cancel();
Expand Down
10 changes: 5 additions & 5 deletions test/async_cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void main() {
var completer = new Completer<String>();
expect(cache.fetch(() => completer.future), completion('Expensive'));
expect(cache.fetch(expectAsync0(() {}, count: 0)), completion('Expensive'));
await completer.complete('Expensive');
completer.complete('Expensive');
});

test('should fetch via a callback again when cache expires', () {
Expand All @@ -58,9 +58,9 @@ void main() {
var timesCalled = 0;
call() async => 'Called ${++timesCalled}';
expect(await cache.fetch(call), 'Called 1');
await cache.invalidate();
cache.invalidate();
expect(await cache.fetch(call), 'Called 2');
await cache.invalidate();
cache.invalidate();
expect(await cache.fetch(call), 'Called 3');
});

Expand Down Expand Up @@ -129,9 +129,9 @@ void main() {
}

expect(await cache.fetchStream(call).toList(), ['Called 1']);
await cache.invalidate();
cache.invalidate();
expect(await cache.fetchStream(call).toList(), ['Called 2']);
await cache.invalidate();
cache.invalidate();
expect(await cache.fetchStream(call).toList(), ['Called 3']);
});

Expand Down
4 changes: 2 additions & 2 deletions test/stream_queue_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ main() {
expect(await events.next, 1);
expect(controller.hasListener, isTrue);

events.cancel(immediate: true);
await expect(controller.hasListener, isFalse);
await events.cancel(immediate: true);
expect(controller.hasListener, isFalse);
});

test("cancels the underlying subscription when called before any event",
Expand Down