subscribe method

Function subscribe(
  1. String key,
  2. Function callback
)

Implementation

Function subscribe(String key, Function callback) {
  String privateKey = randomString(10);
  if (_listeners.containsKey(key)) {
    _listeners[key] = {..._listeners[key]!, privateKey: callback};
  } else {
    _listeners[key] = {privateKey: callback};
  }

  return () {
    _listeners[key]?.remove(privateKey);
  };
}