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); }
internal Task <string> Post(string path, object d = null) { var tcs = new TaskCompletionSource <string>(); 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; socket.Emit("post", new SailsArgs() { url = path, data = d }, callback: (oe) => { tcs.TrySetResult((oe as JsonEncodedEventMessage).Args[0].ToString().Replace("\\", string.Empty).TrimStart('"').TrimEnd('"')); }); return(tcs.Task); }