Files
Beam/Beam/IAsyncEnumeratorExtensions.cs
T
qwsdcvghyu89 056e426572 Enhance async capabilities and refactor project structure
Updated project files for `Beam.Dynamic`, `Beam.Exports`, `Beam.Puppeteer`, `Beam.Temporary.Cli`, and `Beam` to include new XML headers, reorganize property groups, and add project references.

Modified `PuppetedUnitDownloader` to support additional parameters for async transformers. Changed return types in `CommonTransformers` to `AsyncTransformer` for asynchronous processing.

Significant refactoring in `DownloadBuilder`, `DownloadContext`, and `DownloadContextBuilder` to introduce generic parameters and improve context management. Updated `SequentialDownloader`, `SequentialFragmentDownloader`, and `UnitDownloader` to accommodate new async transformer types.

Introduced `TypeExtensions` for unique type name generation and added `UnitFragmentDownloaderBinary` for handling binary downloads. Updated solution file to include the new `aeqw89.Beam` project, ensuring proper references across the solution.

These changes enhance the asynchronous capabilities of the Beam library, improve type safety, and streamline the downloading process.
2025-06-23 20:30:09 +03:00

39 lines
1.5 KiB
C#

namespace Beam {
public static class IAsyncEnumeratorExtensions {
public static async IAsyncEnumerator<T> UnwrapFragmented<T>(this IAsyncEnumerator<Fragment<T>> fragmented) {
if (fragmented is null)
throw new ArgumentNullException();
try {
while(await fragmented.MoveNextAsync().ConfigureAwait(false)) {
if (fragmented.Current is null)
yield break;
if (!fragmented.Current.IsComplete)
yield break;
while (fragmented.Current.TryTake(out var item))
if (item is null)
yield break;
else
yield return item;
}
} finally {
await fragmented.DisposeAsync().ConfigureAwait(false);
}
}
public static async IAsyncEnumerator<Ordered<T>> WrapOrdered<T>(this IAsyncEnumerator<T> enumerator) {
if (enumerator is null)
throw new ArgumentNullException();
try {
int index = 0;
while (await enumerator.MoveNextAsync().ConfigureAwait(false))
if (enumerator.Current is null)
yield break;
else
yield return new Ordered<T>(enumerator.Current, index);
} finally {
await enumerator.DisposeAsync().ConfigureAwait(false);
}
}
}
}