Created
February 19, 2018 02:36
-
-
Save muizidn/0855016cb40b7b4bf340db09b3788d93 to your computer and use it in GitHub Desktop.
RxSwift: Error handling without disposing subscription or Resubscribe after disposed
This file contains hidden or 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
// Setelah print "Fetch Error ..." maka subscription -> onCompleted -> isDisposed (dan tidak bisa fetchProduct lagi) | |
Network.fetchProduct() // Return Observable<[Product]> | |
.subscribe(onNext: { value in | |
print("Product is \(value)") | |
}, onError: { error in | |
print("Fetch Error \(error)") | |
}) | |
.diposed(by: bag) | |
// Jika pakai retry() maka "Fetch Error ..." tidak terpanggil karena 'dipantulkan' oleh retry() | |
Network.fetchProduct() // Return Observable<[Product]> | |
.retry() | |
.subscribe(onNext: { value in | |
print("Product is \(value)") | |
}, onError: { error in | |
print("Fetch Error \(error)") // onError menjadi tidak berguna | |
}) | |
.diposed(by: bag) | |
// Yang saya inginkan | |
// Saat error saya bisa menampilkan error (onError terpanggil) namun subscription tidak diterminate (tidak onComplete) | |
// saat saya fetch lagi subscription mendapat value (onNext terpanggil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment