Skip to content

Add executor parameter to read requests #1473

Open
@bolds07

Description

@bolds07

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions