Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase asynchronous function, what's in the background queue and what's not

Lets say I have this

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

//some code inside of the completion handler})

Please don't read too much into the code snippet asking for more code, I only require a short answer. Where it says, "a bunch of code", assume that its actually some code that's on the MAIN queue. Now, when I write down the observeSingleEvent Firebase completion handler, my analysis on it is this.

  1. observeSingleEvent fetches the snapshot on a background queue as to not block UI thats on the main queue.

  2. Once it fetches the snapshot, the block of code after "in" is now back to the MAIN queue, so its fine to put any UI related code in there.

My whole app is based on this reasoning, so if I'm incorrect, please tell me what's actually going on.

like image 323
slimboy Avatar asked Dec 19 '22 14:12

slimboy


1 Answers

That's indeed how the Firebase Database client works: all network and disk I/O happen off the main thread, then your callbacks/blocks are invoked on the main thread.

like image 86
Frank van Puffelen Avatar answered Jan 11 '23 22:01

Frank van Puffelen