Skip to content

Commit

Permalink
Merge pull request #399 from jellyfin/coroutine-crash-workaround
Browse files Browse the repository at this point in the history
Workaround for coroutines crash
  • Loading branch information
nielsvanvelzen authored May 24, 2021
2 parents 1e0e968 + fb41aeb commit f8accb0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/src/main/java/org/jellyfin/mobile/player/source/Result.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jellyfin.mobile.player.source

class Result<T> private constructor(
val value: T?,
val error: Throwable?,
) {
@Suppress("NOTHING_TO_INLINE")
inline fun getOrNull(): T? = value

@Suppress("UNCHECKED_CAST")
inline fun onSuccess(action: (T) -> Unit): Result<T> {
if (error == null) action(value as T)
return this
}

inline fun onFailure(action: (Throwable) -> Unit): Result<T> {
if (error != null) action(error)
return this
}

companion object {
fun <T> success(value: T) = Result(value, null)

fun <T> failure(error: Throwable) = Result<T>(null, error)
}
}

0 comments on commit f8accb0

Please sign in to comment.