namespace LLama.Examples.Extensions { public static class IAsyncEnumerableExtensions { /// /// Show a console spinner while waiting for the next result /// /// /// public static async IAsyncEnumerable Spinner(this IAsyncEnumerable source) { var enumerator = source.GetAsyncEnumerator(); var characters = new[] { '|', '/', '-', '\\' }; while (true) { var next = enumerator.MoveNextAsync(); var (Left, Top) = Console.GetCursorPosition(); // Keep showing the next spinner character while waiting for "MoveNextAsync" to finish var count = 0; while (!next.IsCompleted) { count = (count + 1) % characters.Length; Console.SetCursorPosition(Left, Top); Console.Write(characters[count]); await Task.Delay(75); } // Clear the spinner character Console.SetCursorPosition(Left, Top); Console.Write(" "); Console.SetCursorPosition(Left, Top); if (!next.Result) break; yield return enumerator.Current; } } } }