public async IAsyncEnumerable <Movie> GetAllMoviesStream() { var dbConnection = CreateDbConnection(); DbCommand dbCommand = null; DbDataReader dbDataReader = null; try { await dbConnection.OpenAsync().ConfigureAwait(false); dbCommand = CommandFactoryMovies.CreateCommandForGetAllMovies(dbConnection); dbDataReader = await dbCommand.ExecuteReaderAsync().ConfigureAwait(false); await foreach (var movie in MapToMoviesStreaming(dbDataReader).ConfigureAwait(false)) { yield return(movie); await Task.Delay(1000); } } finally { dbDataReader.DisposeIfNotNull(); dbCommand.DisposeIfNotNull(); dbConnection.Dispose(); } }
public async Task <IEnumerable <Movie> > GetAllMovies() { var dbConnection = CreateDbConnection(); DbCommand dbCommand = null; DbDataReader dbDataReader = null; try { await dbConnection.OpenAsync().ConfigureAwait(false); dbCommand = CommandFactoryMovies.CreateCommandForGetAllMovies(dbConnection); dbDataReader = await dbCommand.ExecuteReaderAsync().ConfigureAwait(false); return(await MapToMovies(dbDataReader).ConfigureAwait(false)); } finally { dbDataReader.DisposeIfNotNull(); dbCommand.DisposeIfNotNull(); dbConnection.Dispose(); } }