firebase / firebase/firebase-android-sdk

Add executor parameter to read requests

Open
#1,473 3 comments 0 reactions 1 assignee Claimed by @jsdt View on GitHub
api: database type: feature request
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

Description

## What feature would you like to see?
An `Executor` parameter to the method `addListenerForSingleValueEvent ` on realtime database api to allow the result be processed in a background thread.

## How would you use it?
As a standard all firebase apis allow adding `Executor` to allow the task listener process the results on a background thread. for some reason the event "read" doesn't have same behavior.
I know it is very easy to get the results of `addListenerForSingleValueEvent ` and start a new thread to process them... but there ISNT ANY REASON FOR THIS METHOD NOT FOLLOW THE API STRUCTURE... all other methods in all other firebase apis to android return a task which can receive a `Executor`

example

```
FirebaseDatabase.getInstance().getReference("blablabla").removeValue().addOnSuccessListener(AsyncTask.THREAD_POOL_EXECUTOR,something);
FirebaseDatabase.getInstance().getReference("blablabla").setValue(null).addOnSuccessListener(AsyncTask.THREAD_POOL_EXECUTOR,something);
FirebaseAuth.getInstance().signInAnonymously().addOnSuccessListener(AsyncTask.THREAD_POOL_EXECUTOR,something);
FirebaseStorage.getInstance().getReference("blablabla").getFile(file).addOnCompleteListener(AsyncTask.THREAD_POOL_EXECUTOR,something);

FirebaseDatabase.getInstance().getReference("blablabla").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
something
});
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});

```

As it is noticeable in this short snippet the "read" event of firebase database completely breaks the code standard and i dont see one single reason for the realtime database api not having a read method which returns a task that can be processed in the backgrond

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.