public void A_separate_thread_trying_read_a_write_locked_object_should_timeout() { Thread lockThread = new Thread(() => { _value.WriteLock(x => { Thread.Sleep(3.Seconds()); return(x); }); }); lockThread.Start(); Thread.Sleep(500.Milliseconds()); string value = string.Empty; bool locked = _value.ReadLock(1.Seconds(), x => { value = x; }); lockThread.Join(); Assert.IsFalse(locked); //Assert.That(locked, Is.False); Assert.AreEqual(string.Empty, value); //Assert.That(value, Is.EqualTo(string.Empty)); }
public void IncrementRetryCount(string id) { if (string.IsNullOrEmpty(id)) { return; } _messages.WriteLock(x => { x[id] = x.ContainsKey(id) ? x[id] + 1 : 1; }); }
public void Viewed(T item) { _messages.UpgradeableReadLock(x => { if (!x.Contains(item)) { _messages.WriteLock(y => y.Add(item)); } }); }
public UnregisterAction Register(T item) { _items.WriteLock(x => x.Insert(0, item)); return(() => { bool removed = false; _items.WriteLock(x => { removed = x.Remove(item); }); return removed; }); }
public void RegisterTransport(Type transportType) { _transportTypes.WriteLock(x => { if (x.Contains(transportType)) { return; } x.Add(transportType); }); }
/// <summary> /// Connects a message sink to the router /// </summary> /// <param name="sink">The sink to be connected</param> /// <returns>A function to disconnect the sink from the router</returns> public UnsubscribeAction Connect(IPipelineSink <TMessage> sink) { _sinks.WriteLock(sinks => sinks.Add(sink)); return(() => _sinks.WriteLock(sinks => sinks.Remove(sink))); }
public void IncrementRetryCount(string id) { _messages.WriteLock(x => { x[id] = x.ContainsKey(id) ? x[id] + 1 : 1; }); }
public UnsubscribeAction Connect(IPipelineSink <Batch <TMessage, TBatchId> > sink) { _consumerSinks.WriteLock(sinks => sinks.Add(sink)); return(() => _consumerSinks.WriteLock(sinks => sinks.Remove(sink))); }
public void Consume(TMessage message) { _messages.WriteLock(x => x.Enqueue(message)); _messageWaiting.Release(); }
public override void Dispose() { _storage.WriteLock(x => x.Clear()); _storage.Dispose(); }