@@ -139,19 +139,16 @@ func (c *client) WaitForWorkflowInstance(ctx context.Context, instance *workflow
139
139
}
140
140
141
141
func GetWorkflowResult [T any ](ctx context.Context , c Client , instance * workflow.Instance , timeout time.Duration ) (T , error ) {
142
- // Zero result
143
- var z T
144
-
145
142
if err := c .WaitForWorkflowInstance (ctx , instance , timeout ); err != nil {
146
- return z , fmt .Errorf ("workflow did not finish in time: %w" , err )
143
+ return * new ( T ) , fmt .Errorf ("workflow did not finish in time: %w" , err )
147
144
}
148
145
149
146
ic := c .(* client )
150
147
b := ic .backend
151
148
152
149
h , err := b .GetWorkflowInstanceHistory (ctx , instance , nil )
153
150
if err != nil {
154
- return z , fmt .Errorf ("getting workflow history: %w" , err )
151
+ return * new ( T ) , fmt .Errorf ("getting workflow history: %w" , err )
155
152
}
156
153
157
154
// Iterate over history backwards
@@ -161,23 +158,23 @@ func GetWorkflowResult[T any](ctx context.Context, c Client, instance *workflow.
161
158
case history .EventType_WorkflowExecutionFinished :
162
159
a := event .Attributes .(* history.ExecutionCompletedAttributes )
163
160
if a .Error != "" {
164
- return z , errors .New (a .Error )
161
+ return * new ( T ) , errors .New (a .Error )
165
162
}
166
163
167
164
var r T
168
165
if err := converter .DefaultConverter .From (a .Result , & r ); err != nil {
169
- return z , fmt .Errorf ("converting result: %w" , err )
166
+ return * new ( T ) , fmt .Errorf ("converting result: %w" , err )
170
167
}
171
168
172
169
return r , nil
173
170
174
171
case history .EventType_WorkflowExecutionCanceled :
175
- return z , ErrWorkflowCanceled
172
+ return * new ( T ) , ErrWorkflowCanceled
176
173
177
174
case history .EventType_WorkflowExecutionTerminated :
178
- return z , ErrWorkflowTerminated
175
+ return * new ( T ) , ErrWorkflowTerminated
179
176
}
180
177
}
181
178
182
- return z , errors .New ("workflow finished, but could not find result event" )
179
+ return * new ( T ) , errors .New ("workflow finished, but could not find result event" )
183
180
}
0 commit comments