Skip to content

Instantly share code, notes, and snippets.

@omarojo
Last active May 3, 2017 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarojo/512cf0b18eb6952cc4cb19434a6510a1 to your computer and use it in GitHub Desktop.
Save omarojo/512cf0b18eb6952cc4cb19434a6510a1 to your computer and use it in GitHub Desktop.
Polling with Timer
func startPollingComments(){
if let cStream = currentStream, connected == true{
//the code would not continue if its NOT connected. hence the Timer shcedule will not be generated, this stops the polling
let stream = cStream as! FBLiveStream
stream.getLastComments(completion: { (comments, error) in
if (error == nil){
self.onCommentsUpdate?(comments as! [Dictionary<String, Any>])
}
Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false, block: {timer in
self.startPollingComments()
})
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment