@@ -180,19 +180,22 @@ public static async IAsyncEnumerable<StateAtPointInTime<TState>> ProjectState<TS
180
180
Func < TState , ResolvedEvent , TState > evolve ,
181
181
[ EnumeratorCancellation ] CancellationToken ct
182
182
) where TState : notnull {
183
- var state = initialState ;
184
-
185
183
if ( messages is KurrentClient . ReadStreamResult readStreamResult ) {
186
184
if ( await readStreamResult . ReadState . ConfigureAwait ( false ) == ReadState . StreamNotFound ) {
187
- yield return new StateAtPointInTime < TState > ( state ) ;
185
+ yield return new StateAtPointInTime < TState > ( initialState ) ;
188
186
189
187
yield break ;
190
188
}
191
189
}
192
190
191
+ var states = new Dictionary < string , TState > ( ) ;
192
+
193
193
await foreach ( var resolvedEvent in messages . WithCancellation ( ct ) ) {
194
+ var state = states . GetValueOrDefault ( resolvedEvent . OriginalStreamId , initialState ) ;
194
195
state = evolve ( state , resolvedEvent ) ;
195
196
197
+ states [ resolvedEvent . OriginalStreamId ] = state ;
198
+
196
199
yield return new StateAtPointInTime < TState > (
197
200
state ,
198
201
resolvedEvent . Event . EventNumber ,
@@ -210,14 +213,13 @@ public static async Task<StateAtPointInTime<TState>> GetStateAsync<TState>(
210
213
) where TState : notnull {
211
214
StateAtPointInTime < TState > ? stateAtPointInTime = null ;
212
215
213
- options ??= new GetStreamStateOptions < TState > ( ) ;
214
-
215
- if ( options . GetSnapshot != null ) {
216
+ options ??= new GetStreamStateOptions < TState > ( ) ;
217
+
218
+ if ( options . GetSnapshot != null )
216
219
stateAtPointInTime = await options . GetSnapshot (
217
220
GetSnapshotOptions . ForStream ( streamName ) ,
218
221
ct
219
222
) ;
220
- }
221
223
222
224
options . StreamPosition = stateAtPointInTime ? . LastStreamPosition ?? StreamPosition . Start ;
223
225
0 commit comments