Skip to content

Instantly share code, notes, and snippets.

@xandrefreire
Last active September 18, 2017 21:31
Show Gist options
  • Save xandrefreire/62af2b8121dca1db9c9e0a017de47c40 to your computer and use it in GitHub Desktop.
Save xandrefreire/62af2b8121dca1db9c9e0a017de47c40 to your computer and use it in GitHub Desktop.
// anwswer to http://stackoverflow.com/questions/41915285/polling-with-rxswift-and-parse-server
func myObs() -> Observable<Int> {
return Observable<Int>.create { observer in
let sig = Observable<Int>.interval(1.0, scheduler: MainScheduler.instance)
let subscription =
sig.subscribe(onNext: { num in
observer.onNext(num)
if num == 10 {
observer.onCompleted()
}
})
return Disposables.create {
subscription.dispose()
}
}
}
let _ = myObs().subscribe(onNext: {num in
print(num)
})
// OUTPUT
// 0
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment