SHARE
TWEET

Untitled

a guest Sep 20th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let disposeBag = DisposeBag()
  2. var count = 1
  3.  
  4. let sequenceThatErrors = Observable<String>.create { observer in
  5.     observer.onNext("🍎")
  6.     observer.onNext("🍐")
  7.     observer.onNext("🍊")
  8.  
  9.     if count == 1 {
  10.         observer.onError(TestError.test)
  11.         print("Error encountered")
  12.         count += 1
  13.     }
  14.  
  15.     observer.onNext("🐶")
  16.     observer.onNext("🐱")
  17.     observer.onNext("🐭")
  18.     observer.onCompleted()
  19.  
  20.     return Disposables.create()
  21. }
  22.  
  23. sequenceThatErrors
  24.     .retry()
  25.     .subscribe(onNext: { print($0) })
  26.     .disposed(by: disposeBag)
  27.  
  28. // Output:
  29. // 🍎
  30. // 🍐
  31. // 🍊
  32. // Error encountered
  33. // 🍎
  34. // 🍐
  35. // 🍊
  36. // 🐶
  37. // 🐱
  38. // 🐭
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top