'Subscribe the remote to a streams.
This invloves checking if they\'ve missed anything and sending those
updates down if they have. During that time new updates for the stream
are queued and sent once we\'ve sent down any missed updates.'

@defer.inlineCallbacks
def subscribe_to_stream(self, stream_name, token):

    self.replication_streams.discard(stream_name)
    self.connecting_streams.add(stream_name)
    try:
        (updates, current_token) = (yield self.streamer.get_stream_updates(stream_name, token))
        for update in updates:
            (token, row) = (update[0], update[1])
            self.send_command(RdataCommand(stream_name, token, row))
        self.send_command(PositionCommand(stream_name, current_token))
        pending_rdata = self.pending_rdata.pop(stream_name, [])
        for (token, update) in pending_rdata:
            if (token > current_token):
                self.send_command(RdataCommand(stream_name, token, update))
        self.replication_streams.add(stream_name)
    except Exception as e:
        logger.exception('[%s]    Failed    to    handle    REPLICATE    command', self.id())
        self.send_error('failed    to    handle    replicate:    %r', e)
    finally:
        self.connecting_streams.discard(stream_name)
