David-Desmaisons / RateLimiter

C# rate limiting utility
http://david-desmaisons.github.io/RateLimiter/
MIT License
282 stars 34 forks source link

'TimeLimiter' does not contain a definition for 'GetAwaiter' #30

Open KoalaBear84 opened 3 years ago

KoalaBear84 commented 3 years ago

Was trying RateLimiter, but can't get it to work like showed in the Readme / Documentation.

Error CS1061 'TimeLimiter' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'TimeLimiter' could be found (are you missing a using directive or an assembly reference?)

Tried with .NET Framework 4.7.2 and .NET 5.

Is the code changed lately?   image

Code:

using RateLimiter;
using System;
using System.Threading.Tasks;

namespace RateLimiterTest
{
    class Program
    {
        private static readonly TimeLimiter TimeLimiterTest = TimeLimiter.GetFromMaxCountByInterval(20, TimeSpan.FromMinutes(1));

        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            await TimeLimiterTest;

            Console.WriteLine("Finished!");
        }
    }
}

Also it would be nice to use an interval of 5 seconds so you can better see the time differences.

fretje commented 3 years ago

I have the same problem... did you get any further with this?

fretje commented 3 years ago

Ok, I found it. Apparently you need a

using ComposableAsync;

at the top. GetAwaiter is implemented there as an extension method on IDispatcher.