private void AddListener(string functionName, Action <string> callback, string[][] param) { string functionFullName = GetFunctionFullName(functionName); ReconnectLoop().ConfigureAwait(false).GetAwaiter().GetResult(); lock (listeners) { if (!listeners.TryGetValue(functionName, out HubListener listener)) { listeners[functionFullName] = listener = new HubListener { FunctionName = functionName, FunctionFullName = functionFullName, Param = param }; } if (!listener.Callbacks.Contains(callback)) { listener.Callbacks.Add(callback); } } }
private async Task AddListener(string functionName, Func <string, Task> callback, object[][] param) { string functionFullName = GetFunctionFullName(functionName); // ensure connected before adding the listener await EnsureConnected(() => { lock (listeners) { if (!listeners.TryGetValue(functionName, out HubListener listener)) { listeners[functionFullName] = listener = new HubListener { FunctionName = functionName, FunctionFullName = functionFullName, Param = param }; } if (!listener.Callbacks.Contains(callback)) { listener.Callbacks.Add(callback); } } }); }
private void AddListener(string functionName, Action <string> callback, object[][] param) { string functionFullName = GetFunctionFullName(functionName); // ensure connected before adding the listener ReconnectLoop().ContinueWith((t) => { lock (listeners) { if (!listeners.TryGetValue(functionName, out HubListener listener)) { listeners[functionFullName] = listener = new HubListener { FunctionName = functionName, FunctionFullName = functionFullName, Param = param }; } if (!listener.Callbacks.Contains(callback)) { listener.Callbacks.Add(callback); } } }).Sync(); }
private void AddListener(string functionName, Action <string> callback, object[][] param) { string functionFullName = GetFunctionFullName(functionName); // ensure connected before adding the listener ReconnectLoop().ContinueWith((t) => { lock (listeners) { if (!listeners.TryGetValue(functionName, out HubListener listener)) { listeners[functionFullName] = listener = new HubListener { FunctionName = functionName, FunctionFullName = functionFullName, Param = param }; } if (!listener.Callbacks.Contains(callback)) { listener.Callbacks.Add(callback); } Console.WriteLine($"listeners.count={listeners.Count} ++++++++++++++++"); } }).ConfigureAwait(false).GetAwaiter().GetResult(); }