[
https://issues.apache.org/jira/browse/TINKERPOP-1774?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16598773#comment-16598773
]
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_r214371239
--- 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 --
Are you sure that that is still true? I just did a quick test and executed
1 Mio. times `Task.Delay` in parallel with a 10 second delay and the whole test
finished in 11 seconds. Unfortunately I couldn't find any more up-to-date
information about this.
The full test for reference:
```cs
[Fact]
public async Task TimersTest()
{
const int nrTasks = 1000000;
var tasks = new List<Task>(nrTasks);
for (var i = 0; i < nrTasks; i++)
{
tasks.Add(Task.Delay(TimeSpan.FromSeconds(10)));
}
await Task.WhenAll(tasks);
}
```
> 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)