@@ -456,19 +456,25 @@ func genClient(file *protogen.File, service *protogen.Service, g *protogen.Gener
456
456
g .P ("ServerStreams:true," )
457
457
g .P ("StreamName:\" " , method .Desc .Name (), "\" ," )
458
458
g .P ("}" )
459
+ g .P ("ctx,cancel := " , g .QualifiedGoIdent (contextPackage .Ident ("WithCancel" )), "(ctx)" )
459
460
g .P ("stream,e:=c.cc.NewStream(ctx,desc," , pathname , ")" )
460
461
g .P ("if e!=nil{" )
462
+ g .P ("cancel()" )
461
463
g .P ("return e" )
462
464
g .P ("}" )
463
465
g .P ("if e:= stream.SendMsg(req);e!=nil{" )
464
466
g .P (g .QualifiedGoIdent (slogPackage .Ident ("ErrorContext" )), "(ctx,\" [" , pathurl , "] send request failed\" ," , g .QualifiedGoIdent (slogPackage .Ident ("String" )), "(\" error\" ,e.Error()))" )
467
+ g .P ("cancel()" )
465
468
g .P ("return e" )
466
469
g .P ("}" )
467
470
g .P ("if e:=stream.CloseSend();e!=nil{" )
468
471
g .P (g .QualifiedGoIdent (slogPackage .Ident ("ErrorContext" )), "(ctx,\" [" , pathurl , "] send request failed\" ," , g .QualifiedGoIdent (slogPackage .Ident ("String" )), "(\" error\" ,e.Error()))" )
472
+ g .P ("cancel()" )
469
473
g .P ("return e" )
470
474
g .P ("}" )
471
- g .P ("return handler(" , g .QualifiedGoIdent (cgrpcPackage .Ident ("NewServerStreamClientContext" )), "[" , g .QualifiedGoIdent (method .Output .GoIdent ), "](" , pathname , "," , "stream))" )
475
+ g .P ("e=handler(" , g .QualifiedGoIdent (cgrpcPackage .Ident ("NewServerStreamClientContext" )), "[" , g .QualifiedGoIdent (method .Output .GoIdent ), "](" , pathname , "," , "stream))" )
476
+ g .P ("cancel()" )
477
+ g .P ("return e" )
472
478
g .P ("}" )
473
479
}
474
480
if method .Desc .IsStreamingClient () && ! method .Desc .IsStreamingServer () {
@@ -507,12 +513,15 @@ func genClient(file *protogen.File, service *protogen.Service, g *protogen.Gener
507
513
g .P ("ServerStreams:true," )
508
514
g .P ("StreamName:\" " , method .Desc .Name (), "\" ," )
509
515
g .P ("}" )
516
+ g .P ("ctx,cancel := " , g .QualifiedGoIdent (contextPackage .Ident ("WithCancel" )), "(ctx)" )
510
517
g .P ("stream,e:=c.cc.NewStream(ctx,desc," , pathname , ")" )
511
518
g .P ("if e!=nil{" )
519
+ g .P ("cancel()" )
512
520
g .P ("return e" )
513
521
g .P ("}" )
514
522
g .P ("e = handler(" , g .QualifiedGoIdent (cgrpcPackage .Ident ("NewAllStreamClientContext" )), "[" , g .QualifiedGoIdent (method .Input .GoIdent ), "," , g .QualifiedGoIdent (method .Output .GoIdent ), "](" , pathname , ",stream," , pbex .NeedValidate (method .Input ), "))" )
515
523
g .P ("stream.CloseSend()" )
524
+ g .P ("cancel()" )
516
525
g .P ("return e" )
517
526
g .P ("}" )
518
527
}
0 commit comments