'Get all new evnets'

@defer.inlineCallbacks
def get_new_events_for_appservice(self, current_id, limit):

    def get_new_events_for_appservice_txn(txn):
        sql = 'SELECT    e.stream_ordering,    e.event_id    FROM    events    AS    e    WHERE    (SELECT    stream_ordering    FROM    appservice_stream_position)                    <    e.stream_ordering    AND    e.stream_ordering    <=    ?    ORDER    BY    e.stream_ordering    ASC    LIMIT    ?'
        txn.execute(sql, (current_id, limit))
        rows = txn.fetchall()
        upper_bound = current_id
        if (len(rows) == limit):
            upper_bound = rows[(-1)][0]
        return (upper_bound, [row[1] for row in rows])
    (upper_bound, event_ids) = (yield self.runInteraction('get_new_events_for_appservice', get_new_events_for_appservice_txn))
    events = (yield self._get_events(event_ids))
    defer.returnValue((upper_bound, events))
