supabase-community / supabase-kt

A Kotlin Multiplatform Client for Supabase.
https://supabase.com/docs/reference/kotlin/introduction
MIT License
381 stars 37 forks source link

[Question]: How cancel supabase request? #598

Closed clwater closed 4 months ago

clwater commented 4 months ago

General info

What is your question?

How cancel supabase request?

Relevant log output (optional)

When i used functions.invoke(A)
I want cancel other functions.invoke(B) or same repart functions.invoke(A) or other supabse request(auth, database)
jan-tennert commented 4 months ago

That should be possible by just using a custom scope:

val myScope = CoroutineScope(Dispatchers.Default)
myScope.launch {
    supabase.from("countries").select()
}
//somewhere else
myScope.cancel() //This will cancel the job. You will probably need to create a new scope afterward as the old one is cancelled

I'm curious, why do you want to cancel these requests?

clwater commented 4 months ago

@jan-tennert Thanks, I can use the Kotlin method to cancel my request.

My app has some scheduled sync requests, but If the user logs out, I want to cancel this sync request.

jan-tennert commented 4 months ago

Yea, you can do that with a custom coroutine scope.