Skip to content

Instantly share code, notes, and snippets.

@eunjin3786
Created January 25, 2022 10:02
Show Gist options
  • Save eunjin3786/5878292aa65eda0c3e7d56fe806bcc53 to your computer and use it in GitHub Desktop.
Save eunjin3786/5878292aa65eda0c3e7d56fe806bcc53 to your computer and use it in GitHub Desktop.
let single = Single<Int>.error(SomeError())
// 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 error: SomeError()
// TO BE
Task {
do {
let value = try await single.value
print("Got a value:", value)
} catch {
print("Got a error:", error)
}
}
// Prints
Got a error: SomeError()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment