Prev | Index | Next

Waiting for results -- callbacks

class PresenceClient(basic.LineReceiver):

    def __init__(self):
        self.queued = []
    
    def isonline(self, user, callback, errback):
        self.queued.append((callback, errback))
        self.transport.write("ISONLINE "+user)

    def lineReceived(self, line):
        c, e = self.queued.pop(0)
        if line == "YES": c(True)
        elif line == "NO": c(False)
        else:
            e(ProtocolError(line))