public static void TryInvoke(this OnAnyHandler handler, string eventName, SocketIOResponse response) { try { handler(eventName, response); } catch { // The exception is thrown by the user code, so it can be swallowed } }
public virtual async Task Test() { SocketIOResponse result = null; string name = string.Empty; int hiCount = 0; var client = SocketIOCreator.Create(); client.OnConnected += async(sender, e) => { await client.EmitAsync("hi", "onAny"); }; OnAnyHandler handler = (eventName, response) => { result = response; name += eventName; }; client.OnAny(handler); client.On("hi", response => { hiCount++; name += "[on('hi')]"; }); await client.ConnectAsync(); await Task.Delay(200); await client.DisconnectAsync(); Assert.AreEqual("hi[on('hi')]", name); Assert.AreEqual($"{SocketIOCreator.Prefix}onAny", result.GetValue <string>()); client.OffAny(handler); await client.EmitAsync("hi", "onAny2"); await Task.Delay(200); await client.DisconnectAsync(); Assert.AreEqual("hi[on('hi')]", name); Assert.AreEqual(2, hiCount); client.Dispose(); }