Exemplo n.º 1
0
        public Serialize(int numberOfThreads, Func <IMessage, string> getQueueNameFromMessage)
        {
            _messages = new NotifyingMultiQueue <ScheduledTask>();
            _getQueueNameFromMessage = getQueueNameFromMessage;

            _waitForWork = new List <Wait_for_work <ScheduledTask> >();
            for (var i = 0; i < numberOfThreads; i++)
            {
                var wfw = new Wait_for_work <ScheduledTask>(_messages,
                                                            () =>
                {
                    ScheduledTask result;
                    var success = _messages.TryDequeue(Thread.CurrentThread.GetHashCode().ToString(),
                                                       out result);
                    return(new Tuple <bool, ScheduledTask>(success, result));
                });
                wfw.Dequeued += _ => _.ContinueWith(_.Message);
                _waitForWork.Add(wfw);
            }
        }
Exemplo n.º 2
0
        public Serialize(int numberOfThreads, Func<IMessage,string> getQueueNameFromMessage)
        {
            _messages = new NotifyingMultiQueue<ScheduledTask>();
            _getQueueNameFromMessage = getQueueNameFromMessage;

            _waitForWork = new List<Wait_for_work<ScheduledTask>>();
            for (var i = 0; i < numberOfThreads; i++)
            {
                var wfw = new Wait_for_work<ScheduledTask>(_messages,
                                               () =>
                                               {
                                                   ScheduledTask result;
                                                   var success = _messages.TryDequeue(Thread.CurrentThread.GetHashCode().ToString(),
                                                                                      out result);
                                                   return new Tuple<bool, ScheduledTask>(success, result);
                                               });
                wfw.Dequeued += _ => _.ContinueWith(_.Message);
                _waitForWork.Add(wfw);
            }
        }
Exemplo n.º 3
0
 public void Single_worker_takes_from_single_queue()
 {
     _sut.Enqueue("a", "q1");
     Assert.IsTrue(_sut.TryDequeue("w1", out _result));
     Assert.AreEqual("a", _result);
 }