createWatchedStreamController<T> static method
Implementation
static StreamController<T> createWatchedStreamController<T>(
Readable<T> readable,
{bool sync = false}) {
Watcher? watcher;
late final StreamController<T> controller;
void disposer() {
watcher?.dispose();
watcher = null;
}
controller = StreamController<T>.broadcast(
sync: sync,
onListen: () {
watcher = Watcher(
() => readable.value,
(newValue, __) {
controller.add(newValue);
},
when: IMutableCollection.skipNode(readable),
);
},
onCancel: disposer,
);
JFinalizer.attachToJoltAttachments(readable, disposer);
return controller;
}