'Add events to the queue, with the given persist_event options.
Args:
room_id (str):
events_and_contexts (list[(EventBase, EventContext)]):
backfilled (bool):'

def add_to_queue(self, room_id, events_and_contexts, backfilled):

    queue = self._event_persist_queues.setdefault(room_id, deque())
    if queue:
        end_item = queue[(-1)]
        if (end_item.backfilled == backfilled):
            end_item.events_and_contexts.extend(events_and_contexts)
            return end_item.deferred.observe()
    deferred = ObservableDeferred(defer.Deferred())
    queue.append(self._EventPersistQueueItem(events_and_contexts=events_and_contexts, backfilled=backfilled, deferred=deferred))
    return deferred.observe()
