Open
Description
I see two concerns with .Memoize()
, that I would like to discuss before addressing:
Currently, the_error
field is use for both.GetEnumerator()
errors and iteration errors. This is incorrect under the following scenario:Obtain an iterator via.GetEnumerator()
Encounter an error during iteration via.MoveNext()
Attempt to obtain a new iterator.
The expectation is that I would be able to get an iterator, and that it would iterate to the exceptionThe current code shares the_error
field, and so I would get an error in.GetEnumerator()
and not be able to iterate to the error.
- Currently, the
MemoizedEnumerable
incorrectly implements theIDispose
pattern- When an object is disposed, it should be prepared to be GC'd. All future attempts to use any aspect of the object should throw an
ObjectDisposedException
- The current code only throws an
ObjectDisposedException
when the object holds an open iteration after being disposed. The.Dispose()
method is treated as a reset rather than an actual disposal; clearing the current cache and starting a new iteration as if.Skip()
had been called on the original sequence. - If clearing the cache is a desired behavior, it should be done under a
.Clear()
method instead of.Dispose()
.
- When an object is disposed, it should be prepared to be GC'd. All future attempts to use any aspect of the object should throw an
@leandromoh I am happy to update the code to correct these issues, but I would like to understand existing thought patterns if either of the above patterns is intended.
CC: @leandromoh
Metadata
Metadata
Assignees
Labels
No labels