Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
IqResponse.cs
1using System;
3using System.Threading.Tasks;
4
6{
10 public class IqResponse
11 {
12 private readonly TaskCompletionSource<KeyValuePair<string, bool>> xml = new TaskCompletionSource<KeyValuePair<string, bool>>();
13 private readonly DateTime expiresUtc;
14 private readonly string key;
15 private bool resultSet = false;
16
17 internal IqResponse(string Key, DateTime ExpiresUtc)
18 {
19 this.key = Key;
20 this.expiresUtc = ExpiresUtc;
21 }
22
26 public string Key => this.key;
27
31 public DateTime ExpiresUtc => this.expiresUtc;
32
39 internal bool SetResult(string Xml, bool Ok)
40 {
41 lock (this)
42 {
43 if (this.resultSet)
44 return false;
45
46 this.resultSet = true;
47 this.xml.TrySetResult(new KeyValuePair<string, bool>(Xml, Ok));
48
49 return true;
50 }
51 }
52
57 public async Task<KeyValuePair<string, bool>> GetResponse()
58 {
59 return await this.xml.Task;
60 }
61 }
62}
Associates a specific IQ request with an IQ response.
Definition: IqResponse.cs:11
async Task< KeyValuePair< string, bool > > GetResponse()
Gets the response of the IQ request.
Definition: IqResponse.cs:57
DateTime ExpiresUtc
When request expires, in UTC.
Definition: IqResponse.cs:31
string Key
Key of the request.
Definition: IqResponse.cs:26