Guest User

Untitled

a guest
Sep 20th, 2019
96
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