protected override object QueryAndWait(Func <InMemoryState, object> query) { using (var callback = new InMemoryDispatcherCallback(query)) { _queries.Enqueue(callback); if (Volatile.Read(ref _outstandingRequests.Value) == 0) { if (Interlocked.Exchange(ref _outstandingRequests.Value, 1) == 0) { _semaphore.Release(); } } // TODO: Add timeout here – dispatcher thread can fail, and we shouldn't block user code in this case callback.Ready.Wait(); return(callback.Result); } }
protected override object QueryAndWait(Func <InMemoryState, object> query) { using (var callback = new InMemoryDispatcherCallback(query)) { _queries.Enqueue(callback); if (Volatile.Read(ref _outstandingRequests.Value) == 0) { if (Interlocked.Exchange(ref _outstandingRequests.Value, 1) == 0) { _semaphore.Release(); } } if (!callback.Ready.Wait(DefaultQueryTimeout)) { throw new TimeoutException(); } return(callback.Result); } }