public IReactive <bool> MoveNextAsync() { return(Reactive.From <bool>(async resultResolver => { await TaskCollector.With(async tc => { using (ContextualStream <T> childStream = stream.CreateChildWithin(new CSScope(valueScope: InfiniteIntervalScope.Create( RWScope.Read, 0, null)))) using (IAccessContext <enumeratorScope> childEnumContext = context.CreateChild(new enumeratorScope( RWScope.ReadWrite, RWScope.ReadWrite))) { long curNextIndex = await readNextIndex(childEnumContext); CSScope readNextNodeScope = new CSScope(valueScope: InfiniteIntervalScope.Create(RWScope.Read, curNextIndex, curNextIndex + 1)); childStream.Context.RequiredScope = readNextNodeScope; node nextNode; if (curNextIndex == 0) { /* Erste Iteration. */ tc.Add(incrementNextIndex(childEnumContext)); nextNode = await childStream.getFirstNode( childStream.Context); } else { node curCurrentNode = await readCurrentNode(childEnumContext); if (curCurrentNode == null) { throw new InvalidOperationException( "The stream has already " + "been iterated through."); } tc.Add(incrementNextIndex(childEnumContext)); await childStream.Context.UntilAvailable(); nextNode = curCurrentNode.Successor; } resultResolver.Resolve(nextNode != null); childStream.Dispose(); tc.Add(setCurrentNode(nextNode, childEnumContext)); } }); })); }
public IReactive <T> GetCurrentAsync() { return(Reactive.From <T>(async resultResolver => { using (ContextualStream <T> childStream = stream.CreateChildWithin(new CSScope(valueScope: InfiniteIntervalScope.Create( RWScope.Read, 0, null)))) using (IAccessContext <enumeratorScope> childEnumContext = context.CreateChildWithin(new enumeratorScope( RWScope.Read, RWScope.Read))) { long curNextIndex = await readNextIndex(childEnumContext); childEnumContext.RequiredScope = new enumeratorScope(RWScope.Read); CSScope readValueScope = new CSScope(valueScope: InfiniteIntervalScope.Create( RWScope.Read, curNextIndex - 1, curNextIndex)); childStream.Context.RequiredScope = readValueScope; node curNode = await readCurrentNode(childEnumContext); childEnumContext.Dispose(); if (curNode == null) { throw new InvalidOperationException( "The enumerator is already disposed."); } await childStream.Context.UntilAvailable( readValueScope); resultResolver.Resolve(curNode.Value); } })); }