Created
September 21, 2013 21:03
-
-
Save jrusbatch/6654174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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