saveNetworkResponse method

void saveNetworkResponse({
  1. required bool writeToCache,
  2. required Stream<Nip01Event> inputStream,
})

saves network responses in db and then write to response stream if not already in db (useful to avoid duplicates)

Implementation

void saveNetworkResponse({
  required bool writeToCache,
  required Stream<Nip01Event> inputStream,
}) {
  inputStream.listen((event) async {
    Logger.log.t("⛁ got event from network $event ");

    if (writeToCache) {
      await cacheManager.saveEvent(event);
    }
  }, onDone: () {
    //? cannot be implemented as stack insert when the stream closes, because it would screw up subscriptions.
  }, onError: (error) {
    Logger.log.e("⛔ $error ");
  });
}