예제 #1
0
 /// <summary>
 /// 指定秒数後に次の状態に遷移します。
 /// </summary>
 /// <param name="delay">Delay.</param>
 /// <param name="lockKey">Lock key.</param>
 public static void Next(float delay, string lockKey)
 {
     SimpleLock.Lock(lockKey, delay, (System.Action)(() =>
     {
         StateManager.Next();
     }));
 }
예제 #2
0
 public StripedCuckooHashSet(int capacity) : base(capacity)
 {
     _lock = new ILock[2, capacity];
     for (int i = 0; i < 2; i++)
     {
         for (int j = 0; j < capacity; j++)
         {
             _lock[i, j] = new SimpleLock();
         }
     }
 }
        private static async Task InvokeAsync(ThrottleOptions options)
        {
            var middleware = new ThrottleMiddleware(options);

            RequestProcessorCallback next = async context =>
            {
                SimpleLock.Take();

                await Task.Delay(100);

                SimpleLock.Release();
            };

            var requests = Enumerable
                           .Repeat(new Context(new FakeRequest()), 10)
                           .Select(ctx => Task.Run(() => middleware.InvokeAsync(ctx, next)));

            await Task.WhenAll(requests);
        }