once<T> method

void once<T>(
  1. String key,
  2. void handler(
    1. T? value
    ), {
  3. String? scope,
})

Implementation

void once<T>(String key, void Function(T? value) handler,{String? scope}){
  StreamController<T?> receiver  = _controller(key,scope: scope);
  late StreamSubscription<T?> streamSubscription;
  streamSubscription = receiver.stream.listen((data) {
    streamSubscription.cancel();
    handler.call(data);
  });
}