switch_latest 0.1.0 copy "switch_latest: ^0.1.0" to clipboard
switch_latest: ^0.1.0 copied to clipboard

Dart 1 only

A stream transformer for merging a stream of streams into a single stream while only emitting data from the most recent stream

Switch Latest #

A stream transformer for merging a stream of streams into a single stream while only emitting data from the most recent stream

Example #

import 'dart:async';
import 'package:switch_latest/switch_latest.dart';

main() {
  var controller = new StreamController();
  var numbers    = new StreamController();
  var letters    = new StreamController();
  var animals    = new StreamController();

  // Apply the switch latest transformer to the main stream
  var latest = controller.stream.transform(new SwitchLatest());

  // Print the results of items pumped through the stream
  latest.listen(print);

  // Pump the numbers stream through the main stream and emit some numbers
  controller.add(numbers.stream);
  numbers.add(1);
  numbers.add(2);

  // Pump the letters stream through the main stream and try to print some
  // more numbers, then close the numbers stream and emit some letters
  controller.add(letters.stream);
  numbers.add(3);
  numbers.add(4);
  numbers.close();
  letters.add('a');
  letters.add('b');
  letters.close();


  // Now with animals
  controller.add(animals.stream);
  animals.add('Cats');
  animals.add('Dogs');
  animals.close();
  controller.close();
}
0
likes
25
pub points
0%
popularity

Publisher

unverified uploader

A stream transformer for merging a stream of streams into a single stream while only emitting data from the most recent stream

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

merge

More

Packages that depend on switch_latest