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),
detach: true,
debug: const JoltDebugOption.type('Watcher<ToStream>'));
},
onCancel: disposer,
);
JFinalizer.attachToJoltAttachments(readable, () {
disposer();
controller.close();
});
return controller;
}