Refactor fluent download pipelines

This commit is contained in:
qwsdcvghyu89
2025-09-27 15:38:58 +10:00
parent 13c6fbaf5f
commit 94b6c0645c
33 changed files with 518 additions and 451 deletions
+44
View File
@@ -0,0 +1,44 @@
using System.Collections.Concurrent;
using System.Text.Json;
using Beam.Models;
namespace Beam.Fluent;
internal sealed class DownloadStage<RawType, OutType>(DownloadEnumerable<OutType> download) : IDownloadStage<RawType, OutType> {
private IAsyncEnumerable<Ordered<OutType>> _download = download;
public DownloadEnumerable<OutType> AsAsyncEnumerable() {
return new DownloadEnumerable<OutType>(_download.GetAsyncEnumerator());
}
private async IAsyncEnumerable<Ordered<OutType>> _SaveToDirectory(string dir) {
Directory.CreateDirectory(dir);
await foreach (var download in _download) {
await System.IO.File.WriteAllTextAsync(
Path.Combine(dir, $"{Path.GetRandomFileName()}.{download.Order}.json"),
JsonSerializer.Serialize(dir));
yield return download;
}
}
public IDownloadStage<RawType, OutType> SaveToDirectory(string dir) {
_download = _SaveToDirectory(dir);
return this;
}
public IDownloadStage<RawType, OutType> SaveToFiles(IEnumerable<string> files) {
throw new NotImplementedException();
}
public IDownloadStage<RawType, OutType> SaveToMemory(ConcurrentBag<OutType> bag) {
throw new NotImplementedException();
}
public void WaitForDownload() {
throw new NotImplementedException();
}
public Task WaitForDownloadAsync() {
throw new NotImplementedException();
}
}