/// <summary> /// <see cref="ExecuteImpl">Executes the query</see> asynchronously on <see cref="WorkingSet"/> /// </summary> /// <param name="parameterTuple">A tuple with the query parameters</param> /// <returns>A task with the query result</returns> protected TResult Execute(TTuple parameterTuple) { if (null == WorkingSet) { throw new InvalidOperationException("Query has no working set"); } NamespaceDefinition globalScope; if (WorkingSet.TryObtainReadLock(LockTimeout, out globalScope)) { try { return(ExecuteImpl(globalScope, parameterTuple)); } finally { WorkingSet.ReleaseReadLock(); } } throw new TimeoutException(); }
/// <summary> /// <see cref="Execute(Statement)">Executes the query</see> asynchronously on the <see cref="WorkingSet"/> /// </summary> /// <param name="cancellationToken">the cancellation token</param> /// <returns>A task with the query result</returns> public Task <TResult> ExecuteAsync(CancellationToken cancellationToken) { if (null == WorkingSet) { throw new InvalidOperationException("Query has no working set"); } return(Factory.StartNew <TResult>(() => { NamespaceDefinition globalScope; cancellationToken.ThrowIfCancellationRequested(); if (WorkingSet.TryObtainReadLock(LockTimeout, out globalScope)) { try { cancellationToken.ThrowIfCancellationRequested(); return Execute(globalScope); } finally { WorkingSet.ReleaseReadLock(); } } throw new TimeoutException(); })); }
/// <summary> /// <see cref="ExecuteImpl">Executes the query</see> asynchronously on <see cref="WorkingSet"/> /// </summary> /// <param name="parameterTuple">A tuple with the query parameters</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>A task with the query result</returns> protected Task <TResult> ExecuteAsync(TTuple parameterTuple, CancellationToken cancellationToken) { if (null == WorkingSet) { throw new InvalidOperationException("Query has no working set"); } Func <TResult> action = () => { NamespaceDefinition globalScope; cancellationToken.ThrowIfCancellationRequested(); if (WorkingSet.TryObtainReadLock(LockTimeout, out globalScope)) { try { cancellationToken.ThrowIfCancellationRequested(); return(ExecuteImpl(globalScope, parameterTuple)); } finally { WorkingSet.ReleaseReadLock(); } } throw new TimeoutException(); }; return(Factory.StartNew <TResult>(action, cancellationToken)); }