{"action":"created","issue":{"url":"https://api.github.com/repos/PlayFab/consuldotnet/issues/33","labels_url":"https://api.github.com/repos/PlayFab/consuldotnet/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/PlayFab/consuldotnet/issues/33/comments","events_url":"https://api.github.com/repos/PlayFab/consuldotnet/issues/33/events","html_url":"https://github.com/PlayFab/consuldotnet/issues/33","id":126125576,"number":33,"title":"Support for TPL & async await","user":{"login":"PaulNorth","id":13435144,"avatar_url":"https://avatars.githubusercontent.com/u/13435144?v=3","gravatar_id":"","url":"https://api.github.com/users/PaulNorth","html_url":"https://github.com/PaulNorth","followers_url":"https://api.github.com/users/PaulNorth/followers","following_url":"https://api.github.com/users/PaulNorth/following{/other_user}","gists_url":"https://api.github.com/users/PaulNorth/gists{/gist_id}","starred_url":"https://api.github.com/users/PaulNorth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaulNorth/subscriptions","organizations_url":"https://api.github.com/users/PaulNorth/orgs","repos_url":"https://api.github.com/users/PaulNorth/repos","events_url":"https://api.github.com/users/PaulNorth/events{/privacy}","received_events_url":"https://api.github.com/users/PaulNorth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2016-01-12T08:35:27Z","updated_at":"2016-01-13T18:56:27Z","closed_at":null,"body":"I would like to use your library to add support for Consul to Microsoft Orleans (https://github.com/dotnet/orleans) but the lack of async support is a big issue for that project.\r\n\r\nI see there is a PR which has switched the client code to use HttpClient, do you intend to build on this and move to supporting async requests?\r\n\r\nThanks for the work so far!"},"comment":{"url":"https://api.github.com/repos/PlayFab/consuldotnet/issues/comments/171397261","html_url":"https://github.com/PlayFab/consuldotnet/issues/33#issuecomment-171397261","issue_url":"https://api.github.com/repos/PlayFab/consuldotnet/issues/33","id":171397261,"user":{"login":"shayhatsor","id":12084632,"avatar_url":"https://avatars.githubusercontent.com/u/12084632?v=3","gravatar_id":"","url":"https://api.github.com/users/shayhatsor","html_url":"https://github.com/shayhatsor","followers_url":"https://api.github.com/users/shayhatsor/followers","following_url":"https://api.github.com/users/shayhatsor/following{/other_user}","gists_url":"https://api.github.com/users/shayhatsor/gists{/gist_id}","starred_url":"https://api.github.com/users/shayhatsor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shayhatsor/subscriptions","organizations_url":"https://api.github.com/users/shayhatsor/orgs","repos_url":"https://api.github.com/users/shayhatsor/repos","events_url":"https://api.github.com/users/shayhatsor/events{/privacy}","received_events_url":"https://api.github.com/users/shayhatsor/received_events","type":"User","site_admin":false},"created_at":"2016-01-13T18:56:26Z","updated_at":"2016-01-13T18:56:26Z","body":">  I'm also unsure of what you mean by your earlier statement \"follow the async all the way rule to the public surface methods.\" in relation to what you said before: \"1) convert all your library to async except only the public surface sync methods. \"\r\nIs this saying it's fine if Acquire(), Release() etc are not async and use  GetAwaiter().GetResult()  as long as all the calls below that in the call chain are async?\r\n\r\nok, i'll explain again, remember I wrote this:\r\n> 1) convert all your library to async except only the public surface sync methods. this is because having any blocking code called from an async method effectively makes the whole call chain not purely async. don't go there.\r\n\r\n`GetAwaiter().GetResult()` is a **blocking** call. you don't want to block the thread while you're waiting for network response. just use `await` instead .\r\n\r\n> It also seems weird to have lock-style statements be  async  since they're supposed to be guarding critical sections, so it feels like you want blocking here.\r\n\r\nit is weird, but it's what you want. note that you can't await in a normal lock because it is owned by the running thread, which you actually release upon await... so it doesn't really make sense. Instead, you need something that isn't thread related that provides mutual exclusion asynchronously. this is what AsyncLock gives you. Keep in mind that AsyncLock isn't reentant and normal lock is. but I don't see it as a requirement here.\r\n\r\n>One final thing I'm struggling with is AutoSemaphore (and AutoLock) - they're a pair of classes that are supposed to let you do  using (new AutoLock(lockargs)) {something}  and it will do an I/O to Consul, get a lock there, do your thing in the using block, and then the Dispose method does another I/O to unlock.\r\n\r\nwhat you do is this:\r\n* use async factory method instead of the constructor. (make the ctor private)\r\n* use async dispose method instead of the dispose.\r\nthis does mean you can't use `using` anymore, as c# doesn't have an async using yet.\r\nbut you can make your own. I actually did that in [zookeeper](https://github.com/shayhatsor/zookeeper/blob/trunk/src/csharp/src/ZooKeeperNetEx/zookeeper/ZooKeeper.cs#L1140). and an example of usage is [here](https://github.com/dotnet/orleans/blob/master/src/OrleansZooKeeperUtils/ZooKeeperBasedMembershipTable.cs#L129)\r\n\r\n"}}