RetrieveNextBatch() { Seq < Util.Try <ReplayCompletion> > msg; using (var conn = _connectionFactory.GetConnection()) { msg = await Messages(conn, persistenceId, opt.Item1, toSequenceNr, batchSize) .RunWith( ExtSeq.Seq <Util.Try <ReplayCompletion> >(), mat); } var hasMoreEvents = msg.Count == batchSize; //var lastMsg = msg.IsEmpty.LastOrDefault(); Util.Option <long> lastSeq = Util.Option <long> .None; if (msg.IsEmpty == false) { lastSeq = msg.Last.Get().Repr.SequenceNr; } FlowControlEnum nextControl = FlowControlEnum.Unknown; if ((lastSeq.HasValue && lastSeq.Value >= toSequenceNr) || opt.Item1 > toSequenceNr) { nextControl = FlowControlEnum.Stop; } else if (hasMoreEvents) { nextControl = FlowControlEnum.Continue; } else if (refreshInterval.HasValue == false) { nextControl = FlowControlEnum.Stop; } else { nextControl = FlowControlEnum.ContinueDelayed; } long nextFrom = opt.Item1; if (lastSeq.HasValue) { nextFrom = lastSeq.Value + 1; } return new Util.Option <((long, FlowControlEnum), Seq <Util.Try <ReplayCompletion> >)>(( (nextFrom, nextControl), msg)); }
RetrieveNextBatch() { Seq < Util.Try <ReplayCompletion> > msg; using (var conn = _connectionFactory.GetConnection()) { var waited = Messages(conn, persistenceId, opt.Item1, toSequenceNr, batchSize); msg = await waited .RunWith( ExtSeq.Seq <Util.Try <ReplayCompletion> >(), mat); } var hasMoreEvents = msg.Count == batchSize; var lastMsg = msg.LastOrDefault(); Util.Option <long> lastSeq = Util.Option <long> .None; if (lastMsg != null && lastMsg.IsSuccess) { lastSeq = lastMsg.Success.Select(r => r.repr.SequenceNr); } else if (lastMsg != null && lastMsg.Failure.HasValue) { throw lastMsg.Failure.Value; } var hasLastEvent = lastSeq.HasValue && lastSeq.Value >= toSequenceNr; FlowControl nextControl = null; if (hasLastEvent || opt.Item1 > toSequenceNr) { nextControl = FlowControl.Stop.Instance; } else if (hasMoreEvents) { nextControl = FlowControl.Continue.Instance; } else if (refreshInterval.HasValue == false) { nextControl = FlowControl.Stop.Instance; } else { nextControl = FlowControl.ContinueDelayed .Instance; } long nextFrom = 0; if (lastSeq.HasValue) { nextFrom = lastSeq.Value + 1; } else { nextFrom = opt.Item1; } return(new Util.Option <((long, FlowControl), Seq <Util.Try <ReplayCompletion> >)>(( (nextFrom, nextControl), msg))); }