Created
January 25, 2022 10:01
-
-
Save eunjin3786/0ec4bfed8f2c0ecb026252ab5b393110 to your computer and use it in GitHub Desktop.
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
let single = Single<Int>.just(0) | |
// AS IS | |
single.subscribe(onSuccess: { value in | |
print("Got a value:", value) | |
}, onFailure: { error in | |
print("Got a error:", error) | |
}, onDisposed: { | |
}).disposed(by: disposeBag) | |
// Prints | |
Got a value: 0 | |
// TO BE | |
Task { | |
do { | |
let value = try await single.value | |
print("Got a value:", value) | |
} catch { | |
print("Got a error:", error) | |
} | |
} | |
// Prints | |
Got a value: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment