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
class VimeoRepositoryImpl( | |
val vimeoClient: VimeoClient, | |
val factory: SuspendFunctionFactory | |
): VimeoRepository { | |
override suspend fun getDocument(documentUri: String): Result<Document> = | |
factory.convertToSuspendFunction(vimeoClient::getDocument)(documentUri) | |
} | |
} |
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
interface SuspendFunctionFactory { | |
fun <A, T> convertToSuspendFunction ( | |
fn: (A, VimeoCallback<T>) -> Call<T> | |
): suspend (A)-> Result<T> | |
} | |
class VimeoClientSuspendFunctionFactory: SuspendFunctionFactory { |
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
val suspendFunction = convertToSuspendFunction(vimeoClient::getDocument) | |
val result: Result<Document> = suspendFunction(documentUri) |
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
fun <A, T> convertToSuspendFunction ( | |
fn: (A, VimeoCallback<T>) -> Call<T> | |
): suspend (A)-> Result<T> = { a -> | |
suspendCancellableCoroutine { cont -> | |
val call = fn(a, object : VimeoCallback<T>() { | |
override fun success(t: T) { | |
cont.resume(Result.Success(t)) | |
} |
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
suspend fun getDocument(documentUri: String): Result<Document> = | |
suspendCancellableCoroutine<Result<Document>> { cont -> | |
val call = vimeoClient.getDocument(documentUri, object :VimeoCallback<Document>() { | |
override fun success(document: Document) { | |
cont.resume(Result.Success(document)) | |
} | |
override fun failure(error: VimeoError) { |
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
Call<Document> getDocument(@NotNull String uri, @NotNull VimeoCallback<Document> callback) |
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
suspend fun getDocument(documentUri: String): Result<Document> { | |
return suspendCancellableCoroutine<Result<Document>> { cont -> | |
} | |
} |
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
suspend fun getDocument(documentUri: String): Result<Document> { } | |
sealed class Result<T> { | |
data class Success<T>(val data: T): Result<T>() | |
data class Error<T>(val error: VimeoError): Result<T>() | |
} |
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
suspend fun <T> suspendCancellableCoroutine( | |
block: (CancellableContinuation<T>) -> Unit | |
): T |
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
vimeoClient.getDocument(documentUri, object: VimeoCallback<Document>() { | |
override fun success(document: Document) { } | |
override fun failure(error: VimeoError) { } | |
}) |