Skip to content

Commit

Permalink
some minor tweaks to fix racy exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
sugarmanz committed Jul 8, 2024
1 parent c9f99e5 commit 2b42f7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ public open class PlayerViewModel(flows: AsyncFlowIterator) : ViewModel(), Andro
AsyncIterationManager.State.NotStarted -> _state.emit(ManagedPlayerState.NotStarted)
AsyncIterationManager.State.Pending -> _state.emit(ManagedPlayerState.Pending)
AsyncIterationManager.State.Done -> _state.emit(ManagedPlayerState.Done(player.completedState))
is AsyncIterationManager.State.Item<*> -> start(it.value as String)
is AsyncIterationManager.State.Item<*> -> try {
start(it.value as String)
} catch (e: Exception) {
_state.emit(ManagedPlayerState.Error(e))
}
is AsyncIterationManager.State.Error -> _state.emit(ManagedPlayerState.Error(it.error)) // player.fail()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public constructor(
public val runtime: Runtime<*> = explicitRuntime ?: runtimeFactory.create {
debuggable = config.debuggable
coroutineExceptionHandler = config.coroutineExceptionHandler ?: CoroutineExceptionHandler { _, throwable ->
inProgressState?.fail(throwable) ?: logger.error(
if (state !is ReleasedState) inProgressState?.fail(throwable) ?: logger.error(
"Exception caught in Player scope: ${throwable.message}",
throwable.stackTrace.joinToString("\n") {
"\tat $it"
Expand Down

0 comments on commit 2b42f7a

Please sign in to comment.