Skip to content

Instantly share code, notes, and snippets.

@eunjin3786
Created January 25, 2022 10:01
Show Gist options
  • Save eunjin3786/0ec4bfed8f2c0ecb026252ab5b393110 to your computer and use it in GitHub Desktop.
Save eunjin3786/0ec4bfed8f2c0ecb026252ab5b393110 to your computer and use it in GitHub Desktop.
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