Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for coroutines crash #399

Merged
merged 1 commit into from
May 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}