|
|
|
@ -36,12 +36,48 @@ public class MsgCache<T, TReq, TResp>
|
|
|
|
|
{
|
|
|
|
|
_dictionary.Remove(MsgKey + key, out var value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MsgPair<TReq, TResp>
|
|
|
|
|
{
|
|
|
|
|
private readonly ManualResetEvent _lock = new(false);
|
|
|
|
|
private TReq? _req;
|
|
|
|
|
|
|
|
|
|
public TReq? Req
|
|
|
|
|
{
|
|
|
|
|
get => _req;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_req = value;
|
|
|
|
|
ClearResp();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class MsgPair<TReq, TResp>
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
public TReq? Req { get; set; }
|
|
|
|
|
public TResp? Resp { get; set; }
|
|
|
|
|
_lock.WaitOne(timeSpan.Value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_lock.WaitOne();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _resp;
|
|
|
|
|
}
|
|
|
|
|
}
|