cached_streamable 1.1.0 copy "cached_streamable: ^1.1.0" to clipboard
cached_streamable: ^1.1.0 copied to clipboard

outdated

Simple interface for creating a streamable data source that caches it latest value.

cached_streamable #

Simple interface for creating a streamable data source that caches it latest value.

Think of it as an "extended" StreamController.

MIT license style: very good analysis

Usage #

Create your implementation by extending CachedStreamable. Use the cache getter and setter to update the value. You can use any single data type. This example uses int. (cache getter is where you can access the latest data. cache setter is where you can update the cache and notify listeners.)

class CounterRepository extends CachedStreamable<int> {
  CounterRepository() : super(0);

  // Some arbitrary future that updates the internal cache
  Future<void> increment() =>
      Future<void>.delayed(Duration.zero, () => cache = cache + 1);
}
  1. Use the stream to access all the updates to the cache.
Future<void> main() async {
  // prints "0" when first listened to
  final repo = CounterRepository()..stream.listen(print);

  // prints "1"
  await repo.increment();
}
  1. Don't forget to call close when you are done.
await repo.close();
1
likes
0
points
199
downloads

Publisher

unverified uploader

Weekly Downloads

Simple interface for creating a streamable data source that caches it latest value.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on cached_streamable