[ https://issues.apache.org/jira/browse/TINKERPOP-1774?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16598787#comment-16598787 ]
ASF GitHub Bot commented on TINKERPOP-1774: ------------------------------------------- Github user jorgebay commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/903#discussion_r214375950 --- 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 -- hmm... indeed, it looks like in .NET Core it uses a single native timer for all timer instances: https://github.com/dotnet/coreclr/blob/master/src/System.Private.CoreLib/src/System/Threading/Timer.cs I wouldn't know about other runtimes. > 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)