MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / sendRespWithBlockMessage

Method sendRespWithBlockMessage

pkg/wshutil/wshrpc.go:847–875  ·  view source on GitHub ↗
(msg RpcMessage)

Source from the content-addressed store, hash-verified

845}
846
847func (w *WshRpc) sendRespWithBlockMessage(msg RpcMessage) {
848 respCh, rd := w.getResponseCh(msg.ResId)
849 if respCh == nil {
850 return
851 }
852 select {
853 case respCh <- &msg:
854 // normal case, message got sent, just return!
855 return
856 default:
857 // channel is full, we would block...
858 }
859 // log the fact that we're blocking
860 _, noLog := blockingExpMap.Get(msg.ResId)
861 if !noLog {
862 log.Printf("[rpc:%s] blocking on response command:%s route:%s resid:%s\n", w.DebugName, rd.Command, rd.Route, msg.ResId)
863 blockingExpMap.Set(msg.ResId, true, time.Now().Add(time.Second))
864 }
865 ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
866 defer cancel()
867 select {
868 case respCh <- &msg:
869 // message got sent, just return!
870 return
871 case <-ctx.Done():
872 }
873 log.Printf("[rpc:%s] failed to clear response channel (waited 1s), will fail RPC command:%s route:%s resid:%s\n", w.DebugName, rd.Command, rd.Route, msg.ResId)
874 w.unregisterRpc(msg.ResId, nil) // we don't pass an error because the channel is full, it won't work anyway...
875}

Callers 1

runServerMethod · 0.95

Calls 4

getResponseChMethod · 0.95
unregisterRpcMethod · 0.95
GetMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected