Пример #1
0
        public Task Invoke(IDictionary<string, object> env)
        {
            RequestQueue queue;
            if (IsQueueInitialized)
            {
                queue = _queue;
            }
            else
            {
                queue = LazyInitializer.EnsureInitialized(
                    ref _queue,
                    ref _queueInitialized,
                    ref _queueLock,
                    () =>
                    {
                        // Start called once on first request
                        var newQueue = new RequestQueue(_options);
                        newQueue.Start();
                        object value;
                        CancellationToken onAppDisposing = env.TryGetValue("server.OnAppDisposing", out value) ? (CancellationToken)value : CancellationToken.None;
                        if (onAppDisposing != CancellationToken.None)
                        {
                            // Stop called once on app disposing
                            // will drain queue by rejecting
                            onAppDisposing.Register(newQueue.Stop);
                        }
                        return newQueue;
                    });
            }

            var requestInstance = new RequestInstance(env, _next);
            RequestInstance executeInstance = queue.GetInstanceToExecute(requestInstance);
            if (executeInstance != null)
            {
                executeInstance.Execute();
            }
            return requestInstance.Task;
        }
Пример #2
0
 private void CreateRequestQueue()
 {
     _queue = new RequestQueue(_options);
     _queue.Start();
 }