File tree 1 file changed +5
-6
lines changed
ui/kotlinx-coroutines-android/src
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -191,24 +191,23 @@ public suspend fun awaitFrame(): Long {
191
191
}
192
192
}
193
193
return suspendCancellableCoroutine { cont ->
194
- if (Looper .myLooper() == = Looper .getMainLooper()) { // Check if we are already in the main looper thread
195
- updateChoreographerAndPostFrameCallback(cont)
196
- } else { // post into looper thread to figure it out
194
+ if (Dispatchers .Main .immediate.isDispatchNeeded(cont.context)) {
197
195
Dispatchers .Main .dispatch(EmptyCoroutineContext , Runnable {
198
196
updateChoreographerAndPostFrameCallback(cont)
199
197
})
198
+ } else {
199
+ updateChoreographerAndPostFrameCallback(cont)
200
200
}
201
201
}
202
202
}
203
203
204
204
private fun updateChoreographerAndPostFrameCallback (cont : CancellableContinuation <Long >) {
205
- val choreographer = choreographer ? :
206
- Choreographer .getInstance()!! .also { choreographer = it }
205
+ val choreographer = choreographer ? : Choreographer .getInstance()!! .also { choreographer = it }
207
206
postFrameCallback(choreographer, cont)
208
207
}
209
208
210
209
private fun postFrameCallback (choreographer : Choreographer , cont : CancellableContinuation <Long >) {
211
210
choreographer.postFrameCallback { nanos ->
212
- with (cont) { Dispatchers .Main .resumeUndispatched(nanos) }
211
+ with (cont) { Dispatchers .Main .immediate. resumeUndispatched(nanos) }
213
212
}
214
213
}
You can’t perform that action at this time.
0 commit comments