Asynchronous Firebase function, what is in the background and what is not

Let's say that I have it

// a bunch of code...  
FIRDatabase.database.reference.child("somechild").observeSingleEventOfType(.Value, withBlock{(snapshot) in   

//some code inside of the completion handler})

Please do not read too much in the code snippet, asking for more code, I only need a short answer. Where he says “a bunch of code,” suppose it is actually code that is in the MAIN queue. Now, when I write the checkSingleEvent Firebase completion handler, my analysis on it is as follows.

  • observSingleEvent retrieves the snapshot in the background so as not to block the user interface that is in the main queue.

  • After it takes a snapshot, the block of code after "in" is now returned to the MAIN queue, so you can put any code associated with the UI there.

My entire application is based on this reasoning, so if I am mistaken, tell me what really happens.

+4
source share
1 answer

This is how the Firebase database client works: all network and disk I / O operations consist of off the main thread, then your callbacks / blocks are called to the main thread.

+9
source

Source: https://habr.com/ru/post/1652678/


All Articles