window_with_time 0.1.0 window_with_time: ^0.1.0 copied to clipboard
A stream transformer for creating windowed streams based on time from a stream
Window With Time #
A stream transformer for creating windowed streams based on time from a stream
Example #
import 'dart:async';
import 'package:window_with_time/window_with_time.dart';
main() {
var controller = new StreamController();
var ids = 0;
var counter = 0;
var oneSecond = new Duration(seconds: 1);
var twoSeconds = new Duration(seconds: 2);
var transformer = new WindowWithTime(twoSeconds, oneSecond);
var windows = controller.stream.transform(transformer);
var loop = new Timer.periodic(oneSecond, (_) {
controller.add(++counter);
});
windows.listen((stream) {
var id = ++ids;
stream.listen((data) {
print("$id => $data");
});
});
}