@@ -46,21 +46,18 @@ func Execute(p ExecuteParams) (result *Result) {
4646 addExtensionResults (& p , result )
4747 }()
4848
49- resultChannel := make (chan * Result )
50- result = & Result {
51- Extensions : map [ string ] interface {}{},
52- }
49+ resultChannel := make (chan * Result , 2 )
50+
51+ go func () {
52+ result := & Result { }
5353
54- go func (out chan <- * Result , done <- chan struct {}) {
5554 defer func () {
5655 if err := recover (); err != nil {
57- result .AppendErrors (gqlerrors .FormatError (err .(error )))
58- }
59- select {
60- case out <- result :
61- case <- done :
56+ result .Errors = append (result .Errors , gqlerrors .FormatError (err .(error )))
6257 }
58+ resultChannel <- result
6359 }()
60+
6461 exeContext , err := buildExecutionContext (buildExecutionCtxParams {
6562 Schema : p .Schema ,
6663 Root : p .Root ,
@@ -72,26 +69,26 @@ func Execute(p ExecuteParams) (result *Result) {
7269 })
7370
7471 if err != nil {
75- result .AppendErrors (gqlerrors .FormatError (err ))
72+ result .Errors = append (result .Errors , gqlerrors .FormatError (err .(error )))
73+ resultChannel <- result
7674 return
7775 }
7876
79- result = executeOperation (executeOperationParams {
77+ resultChannel <- executeOperation (executeOperationParams {
8078 ExecutionContext : exeContext ,
8179 Root : p .Root ,
8280 Operation : exeContext .Operation ,
8381 })
84-
85- }(resultChannel , ctx .Done ())
82+ }()
8683
8784 select {
8885 case <- ctx .Done ():
89- result .AppendErrors (gqlerrors .FormatError (ctx .Err ()))
86+ result := & Result {}
87+ result .Errors = append (result .Errors , gqlerrors .FormatError (ctx .Err ()))
88+ return result
9089 case r := <- resultChannel :
91- result = r
90+ return r
9291 }
93-
94- return
9592}
9693
9794type buildExecutionCtxParams struct {
0 commit comments