'Implement deferreds'

def refill_buffer(self):

    while 1:
        if len(self.producer_fifo):
            p = self.producer_fifo.first()
            if (p is None):
                if (not self.ac_out_buffer):
                    self.producer_fifo.pop()
                    self.close()
                return
            elif isinstance(p, str):
                self.producer_fifo.pop()
                self.ac_out_buffer += p
                return
            data = p.more()
            if (data is NOT_DONE_YET):
                self.delay = p.delay
                return
            elif data:
                try:
                    self.ac_out_buffer = (self.ac_out_buffer + data)
                except TypeError:
                    self.ac_out_buffer = (as_bytes(self.ac_out_buffer) + as_bytes(data))
                self.delay = False
                return
            else:
                self.producer_fifo.pop()
        else:
            return
