Any ideas of how to convert this ValueCallback int...
# coroutines
s
Any ideas of how to convert this ValueCallback into suspend? evaluateJavascript needs to be called from the main thread failing to do so throws an exception ( All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 2) {3acde0b} called on null, FYI main Looper is Looper (main, tid 2) {3acde0b}))
Copy code
return suspendCoroutine { cont ->
            webView.evaluateJavascript( string ) { result ->
                cont.resume( result )
            }
        }
s
Have you tried this?:
Copy code
return withContext(Dispatchers.Main) {
        suspendCoroutine { cont ->
            webView.evaluateJavascript(string) { result ->
                cont.resume(result)
            }
        }
    }
s
@streetsofboston Thx, that works
s
From the documentation it is not clear whether the lambda, provided to the
suspendCoroutine
, is called in the same context that called the
suspendCoroutine
. But it seems it is indeed called in the same context.
s
yeah, it is