|
|
|
@ -36,12 +36,48 @@ public class MsgCache<T, TReq, TResp>
|
|
|
|
|
{
|
|
|
|
|
_dictionary.Remove(MsgKey + key, out var value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MsgPair<TReq, TResp>
|
|
|
|
|
{
|
|
|
|
|
public TReq? Req { get; set; }
|
|
|
|
|
public TResp? Resp { get; set; }
|
|
|
|
|
private readonly ManualResetEvent _lock = new(false);
|
|
|
|
|
private TReq? _req;
|
|
|
|
|
|
|
|
|
|
public TReq? Req
|
|
|
|
|
{
|
|
|
|
|
get => _req;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_req = value;
|
|
|
|
|
ClearResp();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TResp? _resp;
|
|
|
|
|
|
|
|
|
|
public void ClearResp()
|
|
|
|
|
{
|
|
|
|
|
_resp = default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetResp(TResp? resp)
|
|
|
|
|
{
|
|
|
|
|
_resp = resp;
|
|
|
|
|
_lock.Set();
|
|
|
|
|
_lock.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TResp? GetResp(TimeSpan? timeSpan = default)
|
|
|
|
|
{
|
|
|
|
|
if (timeSpan != null)
|
|
|
|
|
{
|
|
|
|
|
_lock.WaitOne(timeSpan.Value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_lock.WaitOne();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _resp;
|
|
|
|
|
}
|
|
|
|
|
}
|