To many people `async` is old hat now...
But to many of us it's still quite new :)
But, **wow** is it awesome :)
Just like with Linq, to start with it doesn't feel that big a deal, but later - after you've been using it a bit - then you know that you are never going back :)
One of the first `async` components that people come across is `HttpClient`. Using this makes async network code really wonderfully writeable and readable :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var client = new HttpClient(); | |
var msg = await client.GetAsync(string.Format(MovieListUrl, ApiToken, searchTerm)); | |
if (msg.IsSuccessStatusCode) | |
{ | |
using (var stream = await msg.Content.ReadAsStreamAsync()) | |
{ | |
using (var streamReader = new StreamReader(stream)) | |
{ | |
var str = await streamReader.ReadToEndAsync(); | |
var list = await JsonConvert.DeserializeObjectAsync<MovieList>(str); | |
return list; | |
} | |
} | |
} |
Further, when you use `HttpClient` on iOS, it isn't just better looking code - it can also be better performing code - as it can make use of the native iOS HttpHandling instead of the Mono .Net one.
Last year, PaulBetts produced a github repo to assist with this http://log.paulbetts.org/fast-http-with-modernhttpclient/
To integrate that back into the PCL world of MvvmCross, a couple of regular MvvmCross contributors have posted lots of useful links:
stonkingly good work in progress from @Cheesebaron - could HttpClient be put behind an Interface? - https://t.co/kfjMcFI1vl
— MvvmCross (@MvvmCross) November 6, 2013
New Blog - Implementing modernhttpclient in Xamarin and MvvmCross. http://t.co/IlNUV0wqTm @MvvmCross @paulcbetts @xamarinhq
— Michael Ridland (@rid00z) November 7, 2013
This is awesome - and well deserving of badges #6 and #2 for Tomascz and Michael
AWESOMENESS!!!!
... although actually right now I seem to be missing a post... where is the first badge for @rid00z - will go hunt!
No comments:
Post a Comment