[ https://issues.apache.org/jira/browse/TINKERPOP-1774?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16598811#comment-16598811 ]
ASF GitHub Bot commented on TINKERPOP-1774: ------------------------------------------- Github user FlorianHockmann commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/903#discussion_r214384104 --- Diff: gremlin-dotnet/src/Gremlin.Net/Driver/AsyncAutoResetEvent.cs --- @@ -0,0 +1,103 @@ +#region License + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#endregion + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +// The implementation is based on this blog post by Stephen Toub: +// https://blogs.msdn.microsoft.com/pfxteam/2012/02/11/building-async-coordination-primitives-part-2-asyncautoresetevent/ + +namespace Gremlin.Net.Driver +{ + /// <summary> + /// An async version of the AutoResetEvent. + /// </summary> + public class AsyncAutoResetEvent + { + private static readonly Task<bool> CompletedTask = Task.FromResult(true); + private readonly List<TaskCompletionSource<bool>> _waitingTasks = new List<TaskCompletionSource<bool>>(); + private bool _isSignaled; + + /// <summary> + /// Asynchronously waits for this event to be set or until a timeout occurs. + /// </summary> + /// <param name="timeout">A <see cref="TimeSpan"/> that that represents the number of milliseconds to wait.</param> + /// <returns>true if the current instance received a signal before timing out; otherwise, false.</returns> + public async Task<bool> WaitOneAsync(TimeSpan timeout) + { + var tcs = new TaskCompletionSource<bool>(); + var waitTask = WaitForSignalAsync(tcs); + if (waitTask.IsCompleted) return true; + + await Task.WhenAny(waitTask, Task.Delay(timeout)).ConfigureAwait(false); --- End diff -- I just tried the same test with .NET Framework 4.6 and got the same result. This is also in line with [the reference source for .NET Framework 4.7.2](https://referencesource.microsoft.com/#mscorlib/system/threading/timer.cs). Mono seems to use this reference source as a basis [for their implementation](https://github.com/mono/mono/blob/c5b88ec4f323f2bdb7c7d0a595ece28dae66579c/mcs/class/referencesource/mscorlib/system/threading/timer.cs). Using `Task.Delay()` together with `Task.WhenAny()` to time out tasks is also a pattern recommended in the two resources you linked to earlier. So, it would be really strange if it worked only for a small number of tasks. Are you still in favour of a more complicated implementation like such a timer queue you mentioned? > Gremlin .NET: Support min and max sizes in Connection pool > ---------------------------------------------------------- > > Key: TINKERPOP-1774 > URL: https://issues.apache.org/jira/browse/TINKERPOP-1774 > Project: TinkerPop > Issue Type: Improvement > Components: dotnet > Affects Versions: 3.2.7 > Reporter: Jorge Bay > Assignee: Florian Hockmann > Priority: Minor > > Similar to the java connection pool, we should limit the maximum amount of > connections and start with a minimum number. > It would also a good opportunity to remove the synchronous acquisitions of > {{lock}} in the pool implementation. -- This message was sent by Atlassian JIRA (v7.6.3#76005)