deleteNamedApp function

void deleteNamedApp(
  1. String name
)

Destroys the app initNamedApp made under name, and what each product holds on it:

  • Auth: its streams end, and a call still waiting is not answered.
  • Database: open transactions fail, a write still pending fails with a DatabaseException, and each listener gets an error.
  • Storage: transfers are canceled, and other requests are waited for.
  • Functions: calls are waited for.
  • Firestore: open transactions fail, whatever else was pending fails with a FirestoreException, and each listener gets an error.
  • App Check: its token stream ends, and a token request still waiting on a custom provider fails.
  • Remote Config: a fetch is waited for. Its defaults and what it fetched and activated stay on disk under the app's name, where an app made again under the name finds them.

The waits block the caller: about 50 ms each for Storage and Functions when they were used at all, and up to five seconds for each of the five while something is still running. The default app cannot be deleted: every product holds it for the life of the process.

Throws StateError when there is no such app, or when a Database or Firestore transaction, a Storage request, a Functions call or a Remote Config fetch on it outlasted the wait. The app is then as it was, less the transfers that were canceled and the transactions that were ended. A Storage request the SDK is retrying after a server error cannot be interrupted, and keeps the app from being deleted until it gives up: up to two minutes, or ten for a transfer.

An app made again under the same name is a new one. What was set on the old one, an emulator among it, has to be set again.

Implementation

void deleteNamedApp(String name) {
  final n = name.toNativeUtf8();
  try {
    final rc = fdbAppDelete(n.cast());
    if (rc != 0) {
      throw StateError(
        rc == -4
            ? 'app "$name" is busy: a transaction, a Storage request, a '
                  'Functions call or a Remote Config fetch on it is still '
                  'running'
            : 'no app named "$name" to delete ($rc)',
      );
    }
  } finally {
    calloc.free(n);
  }
  for (final deleted in namedAppDeleted) {
    deleted(name);
  }
}