mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
client support for rpc cancel (#249)
This commit is contained in:
parent
00958b8fed
commit
534fcc5d0a
@ -51,7 +51,11 @@ async function* rpcResponseGenerator(
|
||||
return;
|
||||
}
|
||||
const shouldTerminate = yield msg.data;
|
||||
if (shouldTerminate || !msg.cont) {
|
||||
if (shouldTerminate) {
|
||||
sendRpcCancel(reqid);
|
||||
return;
|
||||
}
|
||||
if (!msg.cont) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -65,6 +69,12 @@ async function* rpcResponseGenerator(
|
||||
}
|
||||
}
|
||||
|
||||
function sendRpcCancel(reqid: string) {
|
||||
const rpcMsg: RpcMessage = { reqid: reqid, cancel: true };
|
||||
const wsMsg: WSRpcCommand = { wscommand: "rpc", message: rpcMsg };
|
||||
globalWS.pushMessage(wsMsg);
|
||||
}
|
||||
|
||||
function sendRpcCommand(msg: RpcMessage): AsyncGenerator<RpcMessage, void, boolean> {
|
||||
const wsMsg: WSRpcCommand = { wscommand: "rpc", message: msg };
|
||||
globalWS.pushMessage(wsMsg);
|
||||
|
@ -79,6 +79,13 @@ func generateTSMethodTypes(method reflect.Method, tsTypesMap map[reflect.Type]st
|
||||
}
|
||||
|
||||
func getTSFieldName(field reflect.StructField) string {
|
||||
tsFieldTag := field.Tag.Get("tsfield")
|
||||
if tsFieldTag != "" {
|
||||
if tsFieldTag == "-" {
|
||||
return ""
|
||||
}
|
||||
return tsFieldTag
|
||||
}
|
||||
jsonTag := field.Tag.Get("json")
|
||||
if jsonTag != "" {
|
||||
parts := strings.Split(jsonTag, ",")
|
||||
|
@ -57,7 +57,11 @@ func sendRpcRequestResponseStreamHelper[T any](w *wshutil.WshRpc, command string
|
||||
if err != nil {
|
||||
rtnErr(respChan, err)
|
||||
return respChan
|
||||
} else {
|
||||
}
|
||||
opts.StreamCancelFn = func() {
|
||||
// TODO coordinate the cancel with the for loop below
|
||||
reqHandler.SendCancel()
|
||||
}
|
||||
go func() {
|
||||
defer close(respChan)
|
||||
for {
|
||||
@ -78,6 +82,5 @@ func sendRpcRequestResponseStreamHelper[T any](w *wshutil.WshRpc, command string
|
||||
respChan <- wshrpc.RespOrErrorUnion[T]{Response: respData}
|
||||
}
|
||||
}()
|
||||
}
|
||||
return respChan
|
||||
}
|
||||
|
@ -105,6 +105,8 @@ type RpcOpts struct {
|
||||
Timeout int `json:"timeout,omitempty"`
|
||||
NoResponse bool `json:"noresponse,omitempty"`
|
||||
Route string `json:"route,omitempty"`
|
||||
|
||||
StreamCancelFn func() `json:"-"` // this is an *output* parameter, set by the handler
|
||||
}
|
||||
|
||||
type RpcContext struct {
|
||||
|
@ -76,6 +76,14 @@ func GetRpcSourceFromContext(ctx context.Context) string {
|
||||
return rtn.(*RpcResponseHandler).GetSource()
|
||||
}
|
||||
|
||||
func GetIsCanceledFromContext(ctx context.Context) bool {
|
||||
rtn := ctx.Value(wshRpcRespHandlerContextKey{})
|
||||
if rtn == nil {
|
||||
return false
|
||||
}
|
||||
return rtn.(*RpcResponseHandler).IsCanceled()
|
||||
}
|
||||
|
||||
func GetRpcResponseHandlerFromContext(ctx context.Context) *RpcResponseHandler {
|
||||
rtn := ctx.Value(wshRpcRespHandlerContextKey{})
|
||||
if rtn == nil {
|
||||
|
Loading…
Reference in New Issue
Block a user