Skip to content

Instantly share code, notes, and snippets.

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