Bug 37121 - The SLRequest class doesn't expose an awaitable version of PerformRequest()
Summary: The SLRequest class doesn't expose an awaitable version of PerformRequest()
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.4 (iOS 9.2)
Hardware: All All
: Normal enhancement
Target Milestone: (C7)
Assignee: Manuel de la Peña [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-12-17 14:43 UTC by Fabio Garagiola
Modified: 2016-01-13 17:13 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Fabio Garagiola 2015-12-17 14:43:05 UTC
The (deprecated) TWRequest class, in the Twitter namespace, exposes an awaitable PerformRequestAsync() method. The SLRequest class (in the Social namespace) only exposes a PerformRequest() method which requires a handler as parameter. It should be very useful to have an awaitable version using a TaskCompletionSource wrapper. This is exactly what has been done in the Twitter.TWRequest class.

An awaitable PerformRequestAsync() method should return something like an SLRequestResult (similar to the TWRequestResult in the Twitter namespace).

Here is an extension method to exemplify what I mean:

/// <summary>
/// Async extension to the Social.SLRequest class.
/// </summary>

public static class SLExtension
{
	public static Task<SLRequestResult> PerformRequestAsync (this SLRequest request)
	{
		var tcs = new TaskCompletionSource<SLRequestResult> ();

		request.PerformRequest (delegate (NSData responseData, NSHttpUrlResponse urlResponse, NSError error) {
			if (error != null) {
				tcs.SetException (new NSErrorException (error));
			}
			else {
				tcs.SetResult (new SLRequestResult (responseData, urlResponse, error));
			}
		});
		return tcs.Task;
	}
}

public class SLRequestResult
{
	//
	// Properties
	//
	public NSData ResponseData {
		get;
		set;
	}

	public NSHttpUrlResponse UrlResponse {
		get;
		set;
	}

	public NSError Error {
		get;
		set;
	}

	//
	// Constructor
	//
	public SLRequestResult (NSData responseData, NSHttpUrlResponse urlResponse, NSError error)
	{
		this.ResponseData = responseData;
		this.UrlResponse = urlResponse;
		this.Error = error;
	}
}