MsgCache更新

master
smartwyy 6 months ago
parent dd92a75fa0
commit de9d5ae6fc

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

@ -347,7 +347,6 @@ public class CloudClient : IMqttClientConnectedHandler, IMqttApplicationMessageR
public void SendVehicleCertification(VehicleCertification vehicleCertification) public void SendVehicleCertification(VehicleCertification vehicleCertification)
{ {
this.CarAuth.Req = vehicleCertification; this.CarAuth.Req = vehicleCertification;
this.CarAuth.Resp = null;
this.Publish(vehicleCertification); this.Publish(vehicleCertification);
} }

@ -18,6 +18,6 @@ public class CarAuthResHandler : IBaseHandler
public void Handle(string t) public void Handle(string t)
{ {
VehicleCertificationResp? resp = JsonConvert.DeserializeObject<VehicleCertificationResp>(t); VehicleCertificationResp? resp = JsonConvert.DeserializeObject<VehicleCertificationResp>(t);
CloudClientMgr.CloudClient.CarAuth.Resp = resp; CloudClientMgr.CloudClient.CarAuth.SetResp(resp);
} }
} }
Loading…
Cancel
Save