Skip to content

Commit ace97d2

Browse files
committed
Use delay instead of yield
1 parent d597d48 commit ace97d2

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/util/android.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ internal fun AudioRecord.readAsFlow() = callbackFlow {
4242

4343
while (isActive) {
4444
if (recordingState != AudioRecord.RECORDSTATE_RECORDING) {
45-
// TODO(vguthal): Investigate if both yield and delay are required.
46-
delay(10.milliseconds)
47-
yield()
45+
delay(0)
4846
continue
4947
}
5048
val bytesRead = read(buffer, 0, buffer.size)
5149
if (bytesRead > 0) {
5250
send(buffer.copyOf(bytesRead))
5351
}
54-
yield()
52+
delay(0)
5553
}
5654
}

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/LiveSession.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import kotlinx.coroutines.CoroutineScope
4141
import kotlinx.coroutines.Dispatchers
4242
import kotlinx.coroutines.cancel
4343
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
44+
import kotlinx.coroutines.delay
4445
import kotlinx.coroutines.flow.Flow
4546
import kotlinx.coroutines.flow.buffer
4647
import kotlinx.coroutines.flow.catch
@@ -411,7 +412,7 @@ internal constructor(
411412
if (!enableInterruptions) {
412413
audioHelper?.resumeRecording()
413414
}
414-
yield()
415+
delay(0)
415416
} else {
416417
println("Playing audio data")
417418
/**

0 commit comments

Comments
 (0)