addSSEInterceptor method

bool addSSEInterceptor(
  1. SSEInterceptor interceptor, {
  2. bool isOnly = false,
})

SSE cache pool will deliver sse that matched SSEInterceptor.watchEvents to SSEInterceptor.intercept return result represent is add success, true is added to chain, false is not.

Implementation

bool addSSEInterceptor(SSEInterceptor interceptor, {bool isOnly = false}) {
  assert(interceptor.name.isNotEmpty, "sse interceptor name is empty");
  if (isOnly) {
    SSEInterceptor? result = _interceptors.firstWhereOrNull((i) {
      return i.name == interceptor.name;
    });
    if (result != null) {
      return false;
    }
  }
  _interceptors.add(interceptor);
  interceptor.lifeCycle?.onCreate?.call(interceptor.name);
  slog.df("add interceptor $interceptor isOnly $isOnly", tag: tag);
  return true;
}