ExecuteAsync - would like callback to have an additional RestRequestAsyncHandle parameter

1,977 views
Skip to first unread message

vinkaga

unread,
Aug 30, 2011, 5:39:03 PM8/30/11
to RestSharp
Hello,

I really like addition of RestRequestAsyncHandle to the library in the
last few months. I can collect all RestRequestAsyncHandle in a HashSet
which can be used to abort all pending requests if needed.

One thing is missing though, the callback doesn't contain
RestRequestAsyncHandle parameter. If it were present, that
RestRequestAsyncHandle can be removed from the HashSet. Would this be
useful to others?

Vinay

Andrew Young

unread,
Aug 30, 2011, 6:00:19 PM8/30/11
to rest...@googlegroups.com
Yeah. I think that's a really nice-to-have feature. I'm trying to think of a way to implement this in a way where it keeps the RestClient atomic; RestClient shouldn't have to keep a reference to the handle until the response callback is invoked. I'll keep thinking about this. Any ideas would be welcome.

John Sheehan

unread,
Sep 12, 2011, 2:24:38 AM9/12/11
to rest...@googlegroups.com

Andrew Young

unread,
Sep 12, 2011, 1:38:18 PM9/12/11
to rest...@googlegroups.com
Yeah. That's the one.

Technohead

unread,
Sep 14, 2011, 1:42:42 AM9/14/11
to RestSharp
Hi,
I was looking for sample code as to how to use the ExecuteAsync now
that it takes a callback parameter ( Action<RestRequestAsyncHandle,
RestResponse<T>> callback) but could not find any. All sample code
that I have found, was of the ExecuteAsync before the addition of the
callback. How do you use the updated ExecuteAsync with an anonymous
method?

thanks,
Dennis

On Sep 12, 10:38 am, Andrew Young <andrewdyo...@gmail.com> wrote:
> Yeah. That's the one.
>
>
>
>
>
>
>
> On Sunday, September 11, 2011 at 23:24, John Sheehan wrote:
> > Was this added here?https://github.com/johnsheehan/RestSharp/commit/ba93a289ab8e44e899e96...

Andrew Young

unread,
Sep 14, 2011, 1:18:10 PM9/14/11
to rest...@googlegroups.com
The samples that you see are still valid. You don't need to do anything differently unless you want to make use of the async handle. It doesn't require you to provide any additional parameters. I just exposes a way to abort the request.

There's a sample of how to do this at the bottom of the readme.

Dennis Lee

unread,
Sep 14, 2011, 6:21:01 PM9/14/11
to rest...@googlegroups.com
Thanks Andrew for the response. I had tried that but was getting the error:

Delegate `System.Action<RestSharp.RestRequestAsyncHandle,RestSharp.RestResponse<HotelModel>>' does not take `1' arguments (CS1593) 


                var asyncHandle = restClient.ExecuteAsync<HotelModel>(request, response => {

                        Console.WriteLine(response.Data);

                    });



I was able to solve the problem however, using the following code:

                

                restClient.ExecuteAsync<HotelModel>(request, (restRequestAsyncHandle, restResponse)=>

                {

                    Cache.Add(cacheKey, restResponse.Data);

                    callback(restResponse.Data);

                });

Andrew Young

unread,
Sep 14, 2011, 6:30:08 PM9/14/11
to rest...@googlegroups.com
Yeah I'm sorry, it looks like this new feature changed the API so that it's not backwards compatible. I'm looking into a way to make it backwards compatible so it doesn't break for existing users looking to upgrade to 102.

John Sheehan

unread,
Sep 16, 2011, 4:53:11 PM9/16/11
to rest...@googlegroups.com
102.1 fixes this and makes the async handle optional https://github.com/johnsheehan/RestSharp/downloads or on NuGet
Reply all
Reply to author
Forward
0 new messages