Skip to content

Instantly share code, notes, and snippets.

@dangthaison91
Last active June 1, 2016 09:24
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 dangthaison91/30d35699fd4fef69f810c0e8213743b0 to your computer and use it in GitHub Desktop.
Save dangthaison91/30d35699fd4fef69f810c0e8213743b0 to your computer and use it in GitHub Desktop.
private var lastScheduledWord: dispatch_cancelable_block_t?
private var lastRequest: NSURLSessionTask?
func searchRepository(keyword: String) {
cancel_block(lastScheduledWord)
lastRequest?.cancel()
lastRequest = nil
lastScheduledWord = dispatch_after_delay(0.5) {
lastRequest = findRepository(keyword, success: { repository in
findIssues(repository)
}, failure: { error in
displayError(error)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment