From ca10bc95fcc6f458023c837e107d6613bddc65a2 Mon Sep 17 00:00:00 2001 From: Dave Skender <8432125+DaveSkender@users.noreply.github.com> Date: Thu, 9 Nov 2023 06:09:40 -0500 Subject: [PATCH] add AdlAsync --- src/a-d/Adl/Adl.Api.cs | 9 +++++++++ tests/indicators/a-d/Adl/Adl.Tests.cs | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/a-d/Adl/Adl.Api.cs b/src/a-d/Adl/Adl.Api.cs index 578643174..15a55c42e 100644 --- a/src/a-d/Adl/Adl.Api.cs +++ b/src/a-d/Adl/Adl.Api.cs @@ -12,4 +12,13 @@ public static IEnumerable GetAdl( where TQuote : IQuote => quotes .ToQuoteD() .CalcAdl(smaPeriods); + + // TASK, from TQuote + /// + /// + public static Task> GetAdlAsync( + this IEnumerable quotes, + int? smaPeriods = null) + where TQuote : IQuote => Task.Run(() => quotes + .GetAdl(smaPeriods)); } diff --git a/tests/indicators/a-d/Adl/Adl.Tests.cs b/tests/indicators/a-d/Adl/Adl.Tests.cs index a0a21f4b0..2540ab988 100644 --- a/tests/indicators/a-d/Adl/Adl.Tests.cs +++ b/tests/indicators/a-d/Adl/Adl.Tests.cs @@ -32,6 +32,31 @@ public void Standard() Assert.AreEqual(null, r2.AdlSma); } + [TestMethod] + public async Task Async() + { + List ogList = quotes + .GetAdl() + .ToList(); + + IEnumerable results = await quotes + .GetAdlAsync() + .ConfigureAwait(false); + + List rsList = results.ToList(); + + Assert.AreEqual(ogList.Count, rsList.Count); + + for (int i = 0; i < rsList.Count; i++) + { + AdlResult o = ogList[i]; + AdlResult r = rsList[i]; + + Assert.AreEqual(o.Date, r.Date); + Assert.AreEqual(o.Adl, r.Adl); + } + } + [TestMethod] public void WithSma() {