Skip to content

Instantly share code, notes, and snippets.

@hiddenmemory
Last active August 29, 2015 14:06
Show Gist options
  • Save hiddenmemory/0a9069dd276c7fca263f to your computer and use it in GitHub Desktop.
Save hiddenmemory/0a9069dd276c7fca263f to your computer and use it in GitHub Desktop.
API naive example
class API {
private var firstCompletionHandlers: [() -> ()] = []
private var hasCompletedFirst = false
private func completeFirst() {
hasCompletedFirst = true
// API CALL RESPONSE
if firstCompletionHandlers.count > 0 {
for value in firstCompletionHandlers {
value()
}
firstCompletionHandlers = []
}
}
private func checkFirst(completion: () -> ()) {
if hasCompletedFirst {
completion()
}
else {
firstCompletionHandlers.append(completion)
first()
}
}
func first() {
completeFirst()
}
func second() {
checkFirst {
println("Second API Call")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment