Skip to content

Instantly share code, notes, and snippets.

@jrusbatch
Created September 21, 2013 21:03
Show Gist options
  • Save jrusbatch/6654174 to your computer and use it in GitHub Desktop.
Save jrusbatch/6654174 to your computer and use it in GitHub Desktop.
public static class DbAsyncEnumerableExtensions
{
public static IAsyncEnumerable<T> AsAsyncEnumerable<T>(this IDbAsyncEnumerable<T> source)
{
Check.NotNull(source, "source");
return new DbAsyncEnumerableAdapter<T>(source);
}
private struct DbAsyncEnumerableAdapter<T> : IAsyncEnumerable<T>
{
private readonly IDbAsyncEnumerable<T> source;
public DbAsyncEnumerableAdapter(IDbAsyncEnumerable<T> source)
{
this.source = source;
}
public IAsyncEnumerator<T> GetEnumerator()
{
return new DbAsyncEnumeratorAdapter<T>(source.GetAsyncEnumerator());
}
}
private struct DbAsyncEnumeratorAdapter<T> : IAsyncEnumerator<T>
{
private readonly IDbAsyncEnumerator<T> source;
public DbAsyncEnumeratorAdapter(IDbAsyncEnumerator<T> source)
{
this.source = source;
}
public T Current
{
get { return source.Current; }
}
public Task<bool> MoveNext(CancellationToken cancellationToken)
{
return source.MoveNextAsync(cancellationToken);
}
public void Dispose()
{
source.Dispose();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment