using LibGit; namespace LibGitTest; public class Test2 { public static async Task Run() { List commits = new(); List heads = new(); var repo = new GitRepo(new WebRepoSource("https://git.rory.gay/.fosscord/fosscord-server.git/") { }); var ss = new SemaphoreSlim(12,12); var _heads = repo.GetRefs().GetAsyncEnumerator(); while (await _heads.MoveNextAsync()) { heads.Add(_heads.Current); var isCached = await ((WebRepoSource)repo.RepoSource).HasObjectCached(_heads.Current.CommitId); Console.WriteLine(_heads.Current.Name+ " - cache miss: " + !isCached); if (!isCached) { var _c = _heads.Current.CommitId; #pragma warning disable CS4014 Task.Run(async () => #pragma warning restore CS4014 { await ss.WaitAsync(); Console.WriteLine("hi from task"); var a = new GitRepo(new WebRepoSource("https://git.rory.gay/.fosscord/fosscord-server.git/") { }).GetCommits(_c).GetAsyncEnumerator(); while ( await a.MoveNextAsync() && !await ((WebRepoSource)repo.RepoSource) .HasObjectCached(a.Current.CommitId) ) Console.WriteLine($"Prefetched commit {a.Current.CommitId} with {a.Current.ParentIds.Count()} parents"); Console.WriteLine($"Reached already-cached log: {a.Current.CommitId}"); ss.Release(); }); } } var log = repo.GetCommits(heads.First(x=>x.Name == "refs/heads/master").CommitId).GetAsyncEnumerator(); while (await log.MoveNextAsync()) { commits.Add(log.Current); if (commits.Count % 50 == 0) { // StateHasChanged(); await Task.Delay(1); } Console.WriteLine($"Fetched in-log commit {log.Current.CommitId}, {12-ss.CurrentCount} tasks running"); if (ss.CurrentCount == 12) { Console.WriteLine("All tasks finished"); return; } } } }