Skip to content

Instantly share code, notes, and snippets.

@eunjin3786
Created January 25, 2022 10:16
Show Gist options
  • Save eunjin3786/147230a7f86cbe3fbb9fd85b0e56f9d6 to your computer and use it in GitHub Desktop.
Save eunjin3786/147230a7f86cbe3fbb9fd85b0e56f9d6 to your computer and use it in GitHub Desktop.
let maybe = Maybe<Int>.create { observer in
observer(.error(SomeError()))
return Disposables.create()
}
// AS IS
maybe.subscribe(onSuccess: { value in
print("Got a value:", value)
}, onError: { error in
print("Got a error:", error)
}, onCompleted: {
print("On Completed")
}, onDisposed: {
}).disposed(by: disposeBag)
// Prints
// Got a error: SomeError()
// TO BE
Task {
do {
let value = try await maybe.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