Iterating over AsyncEnumerable and writing to MemoryStream
Mainly a question on how you all would go about this, I am thinking of just initializing a
SemaphoreSlim(1,1)
and waiting while inside the iteration then writing to the memory stream. Any opposition to this? The compiled code inside an AsyncEnumerable seems to be what I'd expect so I would need some locking while writing to the stream regardless.13 Replies
For instance
Why not block outside the foreach?
Or are you concerned about the order going into parquet?
what's the semaphore for?
it seems to be doing nothing here
Correct, WriteToParquet takes in the existing memorystream
My comment on this somehow truncated 😦
Are you rationally worried?
Force synchonization while writing to the MemoryStream
that's the exact same code
it will behave the same way
Is that because it is disposed before the next iteration?
what is disposed
the current enumerator
My main concern was unintentionally writing to the stream concurrently. I'm not all too familiar with AsyncEnumerables
It's possible I suppose that batches could come in the wrong order, we don't know the implementation of batches, but you won't solve that with a semaphore
AsyncEnumerable is essentially just a normal enumerable, but made of tasks instead of normal items
it doesn't inherently make you process items in parallel
this code will still process items one at a time
if you wanted to process items in parallel, you'd have to use Parallel.ForEachAsync
I am seeing the compiler transformations right now yes I see now
Of what it looks like under the hood
Gotcha that makes sense. Thanks