internal void Get(string path) { if (Bootlegger.DEBUGMODE) { sw.Reset(); sw.Start(); } if (socket != null && socket.IsConnected) { socket.Emit("get", new SailsArgs() { url = path, data = new ApiKeyArgs() { apikey = Bootlegger.API_KEY } }, callback: (oe) => { //Console.WriteLine(oe); if (Bootlegger.DEBUGMODE) { sw.Stop(); Bootlegger.FireDebug("get " + path + ": " + sw.ElapsedMilliseconds); } }); } }
internal Task <bool> Get(string path, object d = null) { if (Bootlegger.DEBUGMODE) { sw.Reset(); sw.Start(); } var tcs = new TaskCompletionSource <bool>(); const int timeoutMs = 5000; var ct = new CancellationTokenSource(timeoutMs); ct.Token.Register(() => tcs.TrySetCanceled(), useSynchronizationContext: false); if (d == null) { d = new ApiKeyArgs(); } (d as ApiKeyArgs).apikey = Bootlegger.API_KEY; if (socket != null && socket.IsConnected) { socket.Emit("get", new SailsArgs() { url = path, data = d }, callback: (oe) => { if (Bootlegger.DEBUGMODE) { sw.Stop(); Bootlegger.FireDebug("get " + path + ": " + sw.ElapsedMilliseconds); } tcs.TrySetResult(true); }); //Timer t = new Timer(new TimerCallback((o)=>{ // tcs.TrySetResult(true); //}),null,0,2000); } else { tcs.TrySetResult(true); } return(tcs.Task); }