Skip to content

Commit 2757754

Browse files
committed
Merge branch 'vchirikov-fix-csvwriter'
2 parents e759294 + 2a7076c commit 2757754

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/CsvHelper/CsvWriter.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,9 +506,13 @@ public virtual async Task WriteRecordsAsync(IEnumerable records, CancellationTok
506506
}
507507
finally
508508
{
509-
if (enumerator is IDisposable en)
509+
if (enumerator is IAsyncDisposable asyncDisposable)
510510
{
511-
en.Dispose();
511+
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
512+
}
513+
else if (enumerator is IDisposable disposable)
514+
{
515+
disposable.Dispose();
512516
}
513517
}
514518
}
@@ -566,10 +570,15 @@ public virtual async Task WriteRecordsAsync<T>(IEnumerable<T> records, Cancellat
566570
}
567571
finally
568572
{
569-
if (enumerator is IDisposable en)
573+
if (enumerator is IAsyncDisposable asyncDisposable)
570574
{
571-
en.Dispose();
575+
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
572576
}
577+
else if (enumerator is IDisposable disposable)
578+
{
579+
disposable.Dispose();
580+
}
581+
573582
}
574583
}
575584

@@ -626,9 +635,13 @@ public virtual async Task WriteRecordsAsync<T>(IAsyncEnumerable<T> records, Canc
626635
}
627636
finally
628637
{
629-
if (enumerator is IDisposable en)
638+
if (enumerator is IAsyncDisposable asyncDisposable)
630639
{
631-
en.Dispose();
640+
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
641+
}
642+
else if (enumerator is IDisposable disposable)
643+
{
644+
disposable.Dispose();
632645
}
633646
}
634647
}

0 commit comments

Comments
 (0)