-
-
Notifications
You must be signed in to change notification settings - Fork 43
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 #346 from nielsvanvelzen/java-continuation
Rewrite Java callback helpers to support error handling and non-api functions
- Loading branch information
Showing
9 changed files
with
116 additions
and
95 deletions.
There are no files selected for viewing
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
13 changes: 0 additions & 13 deletions
13
jellyfin-api/src/commonMain/kotlin/org/jellyfin/sdk/api/client/compatibility/JavaCallback.kt
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...n-api/src/commonMain/kotlin/org/jellyfin/sdk/api/client/compatibility/JavaDataCallback.kt
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
.../src/jvmMain/kotlin/org/jellyfin/sdk/api/client/compatibility/JavaResponseContinuation.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,17 @@ | ||
package org.jellyfin.sdk.api.client.compatibility | ||
|
||
import org.jellyfin.sdk.api.client.Response | ||
import kotlin.coroutines.Continuation | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
|
||
public abstract class JavaResponseContinuation<T> : Continuation<Response<T>> { | ||
override val context: CoroutineContext = EmptyCoroutineContext | ||
override fun resumeWith(result: Result<Response<T>>): Unit = result.fold( | ||
onSuccess = { onResponse(it.content) }, | ||
onFailure = ::onError, | ||
) | ||
|
||
public abstract fun onResponse(response: T) | ||
public open fun onError(error: Throwable): Unit = throw error | ||
} |
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
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
16 changes: 16 additions & 0 deletions
16
jellyfin-core/src/jvmCommonMain/kotlin/org/jellyfin/sdk/compatibility/JavaContinuation.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,16 @@ | ||
package org.jellyfin.sdk.compatibility | ||
|
||
import kotlin.coroutines.Continuation | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
|
||
public abstract class JavaContinuation<T> : Continuation<T> { | ||
override val context: CoroutineContext = EmptyCoroutineContext | ||
override fun resumeWith(result: Result<T>): Unit = result.fold( | ||
onSuccess = ::onSuccess, | ||
onFailure = ::onError, | ||
) | ||
|
||
public abstract fun onSuccess(result: T) | ||
public open fun onError(error: Throwable): Unit = throw error | ||
} |
2 changes: 1 addition & 1 deletion
2
...n/sdk/discovery/compatibility/JavaFlow.kt → ...rg/jellyfin/sdk/compatibility/JavaFlow.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
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