Last active
May 19, 2020 07:20
-
-
Save uOOOO/b0f0945cb389a04f3ae50e8e770c530f to your computer and use it in GitHub Desktop.
Kotlin Native Reaktive -> RxSwift
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
import YourMPPFramework | |
import RxSwift | |
class KtError: Error { | |
let error: KotlinThrowable | |
init(_ error: KotlinThrowable) { | |
self.error = error | |
} | |
} | |
func toRxSwift<T>(_ source: ReaktiveSingleWrapper<T>) -> Single<T> { | |
return Single<T>.create { observer -> Disposable in | |
let disposable = source.subscribe( | |
isThreadLocal: true, | |
onSubscribe: nil, | |
onError: { error in | |
observer(.error(KtError(error))) | |
}, | |
onSuccess: { value in | |
observer(.success(value!)) | |
} | |
) | |
return Disposables.create { disposable.dispose() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment