protected override void PerformWork(IList<ArraySegment<Message>> items, out int totalCount, out object state)
{
// The list of cursors represent (streamid, payloadid)
var nextCursors = new ulong?[_cursors.Count];
totalCount = 0;
// Get the enumerator so that we can extract messages for this subscription
IEnumerator<Tuple<ScaleoutMapping, int>> enumerator = GetMappings().GetEnumerator();
while (totalCount < MaxMessages && enumerator.MoveNext())
{
ScaleoutMapping mapping = enumerator.Current.Item1;
int streamIndex = enumerator.Current.Item2;
ulong? nextCursor = nextCursors[streamIndex];
// Only keep going with this stream if the cursor we're looking at is bigger than
// anything we already processed
if (nextCursor == null || mapping.Id > nextCursor)
{
ulong mappingId = ExtractMessages(streamIndex, mapping, items, ref totalCount);
// Update the cursor id
nextCursors[streamIndex] = mappingId;
}
}
state = nextCursors;
}