Skip to content

Instantly share code, notes, and snippets.

@dokipen
Created August 15, 2011 19:01
Show Gist options
  • Select an option

  • Save dokipen/1147454 to your computer and use it in GitHub Desktop.

Select an option

Save dokipen/1147454 to your computer and use it in GitHub Desktop.
class ResponseHandler:
def __init__(callback):
self.counter = 0
self.callback = callback
def start:
self.counter += 1 # lock
def _on_response:
self.counter -= 1
if self.counter == 0:
self.callback()
def add_call(url):
self.counter += 1
fetch(url, self._on_response)
def end:
self.counter -= 1
if self.counter == 0:
self.callback()
rh = ResponseHandler(mycallback)
rh.start()
rh.add_call(myurl1)
rh.add_call(myurl2)
rh.add_call(myurl3)
rh.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment