Created
August 15, 2011 19:01
-
-
Save dokipen/1147454 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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