Last active
December 31, 2015 09:59
-
-
Save evilbloodydemon/7970686 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public async Task<string> Get(int id) | |
| { | |
| using (var conn = new RedisConnection("localhost")) | |
| { | |
| await conn.Open(); | |
| var channel = conn.GetOpenSubscriberChannel(); | |
| try | |
| { | |
| var result = string.Empty; | |
| var tcs = new TaskCompletionSource<bool>(); | |
| await channel.Subscribe("artemis", (s, bytes) => | |
| { | |
| try | |
| { | |
| result = Encoding.UTF8.GetString(bytes); | |
| tcs.SetResult(true); | |
| } | |
| catch (Exception e) | |
| { | |
| tcs.SetException(e); | |
| } | |
| }); | |
| await Task.WhenAny(new[] | |
| { | |
| tcs.Task, | |
| Task.Delay(TimeSpan.FromSeconds(25)) | |
| }); | |
| return result; | |
| } | |
| catch (Exception) | |
| { | |
| return String.Empty; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment