https://supabase.com/ logo
#javascript
Title
# javascript
a

akaban

09/10/2021, 2:26 PM
Hello, I'm trying to understand how does the supabase-js library works, it seems like to me that the query building methods return a
PostgresFilterBuilder
object that contains all of the information of the request but the actual request will only be made when I await for this object. This is maybe a javascript classic thing to do but it seems strange that I have an object that can also behaves like a promise when we await. Can someone show me an example of supabase request without
await
? This could help me understand I think, thanks a lot !
j

jcarenza

09/10/2021, 2:51 PM
it likely is firing, you're just not receiving the result when it completes
if you try and log it immediately it will be empty (or a constructor) because the actual operation has not yet returned
which is why you have to await, or read the response of the .then()
a

akaban

09/10/2021, 2:53 PM
Maybe it takes some time then because I have the supabase dashboard on another screen and I can tell you that the only way to have the insert actually happen is to await for the object 😅
s

Scott P

09/10/2021, 2:54 PM
You should still be able to see the network request in the browser dev console, even if you don't await it - you just won't get the results in your code, since the event loop believes you're done with that request and don't care to process it further. The promise paradigm was added because callbacks inside callbacks inside callbacks became extremely difficult to manage (Google 'Callback pyramid of doom' if you want more details). Promises helped make things easier to manage, but I know it took me a long time to understand how things flowed through them. Async-await was added for this reason, and it made code easier to understand since it followed a logical flow from top-to-bottom - very similar to how synchronous code reads, but without the blocking/performance hit that sync code has.
a

akaban

09/10/2021, 2:56 PM
Ok thanks a lot, very clear ! 🙂