diff --git a/lib/src/async_cache.dart b/lib/src/async_cache.dart index 8c25267..53084ca 100644 --- a/lib/src/async_cache.dart +++ b/lib/src/async_cache.dart @@ -37,13 +37,6 @@ class AsyncCache { /// 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] @@ -51,6 +44,13 @@ class AsyncCache { /// 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. /// @@ -90,7 +90,9 @@ class AsyncCache { /// 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(); diff --git a/test/async_cache_test.dart b/test/async_cache_test.dart index 747835b..a4f452f 100644 --- a/test/async_cache_test.dart +++ b/test/async_cache_test.dart @@ -32,7 +32,7 @@ void main() { var completer = new Completer(); 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', () { @@ -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'); }); @@ -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']); }); diff --git a/test/stream_queue_test.dart b/test/stream_queue_test.dart index 32cc505..37dedb9 100644 --- a/test/stream_queue_test.dart +++ b/test/stream_queue_test.dart @@ -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",