internal RestRequestAsyncHandle ExecuteAsync(RestRequest restrequest, Action <RestResponse, RestRequestAsyncHandle> callback)
        {
            var asyncHandle = new RestRequestAsyncHandle();

            Action <RestResponse> responseCallback = r => callback(r, asyncHandle);

            var webrequest = this.WebRequest.ConfigureRequest(this, restrequest);

            _timeoutState = new TimeOutState {
                Request = webrequest
            };

            var asyncResult = webrequest.BeginGetResponse(r => ProcessHttpWebResponseCallback(r, responseCallback), webrequest);

            if (Timeout != 0)
            {
                ThreadPool.RegisterWaitForSingleObject(asyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _timeoutState, this.Timeout, true);
            }

            asyncHandle.WebRequest = webrequest;
            return(asyncHandle);
        }
 private void DeserializeResponse <T>(RestRequest request, Action <RestResponse <T>, RestRequestAsyncHandle> callback, RestResponse response, RestRequestAsyncHandle asyncHandle)
 {
     callback(Deserialize <T>(request, response), asyncHandle);
 }