Hi, can i convert this Firebase Phone Auth code to...
# coroutines
k
Hi, can i convert this Firebase Phone Auth code to coroutines friendly, in below method i have two options first is that i can scope this call to activity and second is that i can add some Executor(which i don't know how works). but here i don't want this request to be scoped on Activity because i don't want this request inside Activity instead i want to move it inside ViewModel or Repository.
Copy code
phoneAuth.verifyPhoneNumber(
number, 1, TimeUnit.MINUTES,
executor or Activity // but here i don't wanna scope it to activity instead i want to use it inside ViewModel using coroutines
,authCallback)
l
You can create an executor that dispatches to a coroutine dispatcher.
k
@louiscad do you have any docs about it or any sample code, because i did not worked with executors
l
You'll also need
suspendCancellableCoroutine
to wrap the callback. @Kulwinder Singh If it's still "not working", please specific about what doesn't work exactly and what you tried.
k
I thought about it but what should i use at place of
executor/activity
parameter those are not nullable
l
Executor
is interface, look. You can implement it and pass the runnables to a coroutine dispatcher.
g
as usual terrible API from Firebase Attempt to make thing easier for “common developer” ™ makes thinks awkward for real developers
it even doesn’t follow other similar APIs from Google, which usually use Handler to deliver result
anyway, use Executor is right solution in this case, just implement it (as i see, it even may be empty, no need to dispatch)