Skip to content

FR: Revising the Threading Model and Async APIs #55

@hiranya911

Description

@hiranya911

There are several issues in the Admin SDK with respect to how it creates and uses threads:

  1. Most public APIs are asynchronous, and returns Task instances. This tends to make implementing simple use cases unnecessarily complex (e.g. creating a custom token and sending back as a servlet response).
  2. Main thread pool is initialized statically, and not configurable.
  3. ThreadFactory is initialized statically, and not configurable.
  4. Tasks API is visible to user code. A user can kick off arbitrary background tasks using this API, which will get executed on the main thread pool of the SDK, un-regulated.

In order to address these limitations, we can consider the following changes:

  • Expose synchronous/blocking variants of public APIs where it makes sense (most notably at FirebaseAuth).
BlockingFirebaseAuth auth = FirebaseAuth.getBlockingInstance(); String customToken = auth.createCustomToken("user1"); 
  • Make the thread pool and thread factory configurable via app options.
  • Hide or decommission the Tasks API. We can consider using the ApiFutures from Google Cloud Commons (this is similar to Guava's ListenableFutures) as a replacement.
FirebaseAuth auth = FirebaseAuth.getInstance(); ApiFuture<String> customTokenFuture = auth.createCustomToken("user1"); // The following should not be supported // Tasks.call(new Callable(){...}); 

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions