The body of an async-iterator method must contain a 'yield' statement #2609
Replies: 15 comments 1 reply
-
yield break? |
Beta Was this translation helpful? Give feedback.
-
That will not help me differentiate between a stream that does not exist and a stream that does exist but has nothing in it. |
Beta Was this translation helpful? Give feedback.
-
Seems like you might need Task<IAsyncEnumerable<StreamMessage>>? |
Beta Was this translation helpful? Give feedback.
-
Same issue as the tuple solution. I would have to await it twice which is ugly. |
Beta Was this translation helpful? Give feedback.
-
You're dealing with two different asynchronous operations, using |
Beta Was this translation helpful? Give feedback.
-
Actually, if you declare var result = await ReadStreamBackwards(...);
if (result is StreamNotFound) {
Console.WriteLine("The stream wasn't found, yo.");
return;
}
var messages = await result.ToArrayAsync();
// do stuff with the array here Sure, if you plan on consuming the The method can't return an |
Beta Was this translation helpful? Give feedback.
-
@thefringeninja - Why not consider adding an out argument of type Or return an new object that contains a |
Beta Was this translation helpful? Give feedback.
-
@Korporal It's async. Async methods can't have out parameters. |
Beta Was this translation helpful? Give feedback.
-
@canton7 @thefringeninja - OK so create a class that implements something like this: public interface IExistentialAsyncStream
{
IAsyncEnumerable<StreamMessage> BackwardMessageStream { get; }
bool StreamExists { get; }
} and have or possibly: public interface IExistentialAsyncStream<T>
{
IAsyncEnumerable<T> BackwardMessageStream { get; }
bool StreamExists { get; }
} |
Beta Was this translation helpful? Give feedback.
-
I usually use tuples for this @Korporal |
Beta Was this translation helpful? Give feedback.
-
After thinking about it I think I will go with @Korporal's or @YairHalberstadt's suggestion and just wrap it, and bite the bullet on the double async. However, after playing with this, it seems to me anyway that something is missing. I can return a 'task like object' in an async method, but I cannot implement Thanks for all the help! |
Beta Was this translation helpful? Give feedback.
-
I wonder why do you need to specialcase empty stream? You surely don't specialcase empty |
Beta Was this translation helpful? Give feedback.
-
Because this is for a stream store database - event sourced, domain driven design. https://github.com/yreynhout/AggregateSource/blob/master/src/EventStore/AggregateSource.EventStore.IntegratedTests/AsyncRepositoryTests.cs#L73 |
Beta Was this translation helpful? Give feedback.
-
@thefringeninja - I'm curious about the problem you're seeing and I'd like to understand it more, can you possibly craft a simpler example of the problem so I can more easily see it? Get rid of stream and backwards and see if you can give a simple abstract example of the problem you're seeing. My solution was just a way of representing what I thought you were driving at, but it seems its deeper... |
Beta Was this translation helpful? Give feedback.
-
Well, i've been iterating on this a lot today, and figured out how to get rid of the double await. Turns out I don't need it if I implement public async IAsyncEnumerable<StreamMessage> ReadStreamBackwards(
StreamId streamId,
int fromVersionInclusive,
int maxCount,
bool prefetchJsonData = true,
CancellationToken cancellationToken = default)
{
Ensure.That(fromVersionInclusive, nameof(fromVersionInclusive)).IsGte(-1);
Ensure.That(maxCount, nameof(maxCount)).IsGte(1);
GuardAgainstDisposed();
cancellationToken.ThrowIfCancellationRequested();
Task<ReadStreamPage> Read(CancellationToken ct)
=> ReadStreamBackwardsInternal(streamId, fromVersionInclusive, maxCount, prefetchJsonData, ReadNext, ct); // returns the first page
Task<ReadStreamPage> ReadNext(int nextVersion, CancellationToken ct)
=> ReadStreamBackwardsInternal(streamId, nextVersion, maxCount, prefetchJsonData, ReadNext, ct); // returns the next Page
return new ReadStreamResult(Read, FilterExpired);
} and |
Beta Was this translation helpful? Give feedback.
-
I have this method that ultimately reads from a database, and I want to differentiate between a stream not existing, vs existing but being empty:
Then then caller could simply do
My alternatives are:
Is it at all possible to get what I want without resorting to the alternatives?
Beta Was this translation helpful? Give feedback.
All reactions