Some RX extensions I have created

175 views
Skip to first unread message

Sergey A

unread,
Jun 3, 2011, 1:39:35 PM6/3/11
to RestSharp
Maybe this is not a right place to submit these, but please forgive me
- I'm new to open source ;) With these you can do sync calls in SL
like

response = Client.ExecuteAsync(request).First();

...............................................................
public static class ObservableEx
{
public static IObservable<TResult> FromCallbackPattern<T,
TResult>(T param, Action<T, Action<TResult>> asyncCall)
{
return Observable
.Create<TResult>(observer =>
{
var subscribed = true;
asyncCall(param, value =>
{
if (!subscribed) return;
observer.OnNext(value);
observer.OnCompleted();
});
return () =>
{
subscribed = false;
};
});
}

public static IObservable<string> ExecuteAsync(this RestClient
client, RestRequest request)
{
Action<RestRequest, Action<RestResponse>> callback = (r,
a) => client.ExecuteAsync(r, a);
return FromCallbackPattern(request, callback).Select(x =>
x.Content);
}

public static IObservable<T> ExecuteAsync<T>(this RestClient
client, RestRequest request) where T : new()
{
Action<RestRequest, Action<RestResponse<T>>> callback =
(r, a) => client.ExecuteAsync(r, a);
return FromCallbackPattern(request, callback).Select(x =>
x.Data);
}
}

John Sheehan

unread,
Jun 3, 2011, 11:06:57 PM6/3/11
to rest...@googlegroups.com
I haven't used Rx at all, but I think you should create a GitHub repo
for this just so it's out there for others to see if they're
interested. And then I have something I can link to when people ask
about Rx.
Reply all
Reply to author
Forward
0 new messages