-
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #399 from jellyfin/coroutine-crash-workaround
Workaround for coroutines crash
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
app/src/main/java/org/jellyfin/mobile/player/source/Result.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |