Skip to content

Commit 496cf6b

Browse files
committed

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

polycode/context.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type WorkflowContext interface {
2121
BaseContext
2222
Service(service string) *RemoteServiceBuilder
2323
Controller(controller string) RemoteController
24-
Function(function func(input any) (any, error)) Function
24+
Memo(getter func() (any, error)) Response
2525
}
2626

2727
type ApiContext interface {
@@ -86,8 +86,9 @@ func (s ContextImpl) Controller(controller string) RemoteController {
8686
return RemoteController{ctx: s.ctx, sessionId: s.sessionId, controller: controller, serviceClient: s.serviceClient}
8787
}
8888

89-
func (s ContextImpl) Function(function func(input any) (any, error)) Function {
90-
return Function{ctx: s.ctx, sessionId: s.sessionId, function: function, serviceClient: s.serviceClient}
89+
func (s ContextImpl) Memo(getter func() (any, error)) Response {
90+
m := Memo{ctx: s.ctx, sessionId: s.sessionId, getter: getter, serviceClient: s.serviceClient}
91+
return m.Get()
9192
}
9293

9394
func (s ContextImpl) ServiceExec(req ExecServiceExtendedRequest) (ExecServiceResponse, error) {

polycode/service.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@ func (r RemoteController) RequestReply(options TaskOptions, path string, apiReq
133133
return output.Response, nil
134134
}
135135

136-
type Function struct {
136+
type Memo struct {
137137
ctx context.Context
138138
sessionId string
139139
serviceClient *ServiceClient
140-
function func(input any) (any, error)
140+
getter func() (any, error)
141141
}
142142

143-
func (f Function) Exec(input any) Response {
143+
func (f Memo) Get() Response {
144144
req1 := ExecFuncRequest{
145-
Input: input,
145+
Input: nil,
146146
}
147147

148148
res1, err := f.serviceClient.ExecFunc(f.sessionId, req1)
@@ -163,7 +163,7 @@ func (f Function) Exec(input any) Response {
163163
}
164164
}
165165

166-
output, err := f.function(input)
166+
output, err := f.getter()
167167
var response Response
168168
if err != nil {
169169
response = Response{
@@ -180,7 +180,7 @@ func (f Function) Exec(input any) Response {
180180
}
181181

182182
req2 := ExecFuncResult{
183-
Input: input,
183+
Input: nil,
184184
Output: response.output,
185185
IsError: response.isError,
186186
Error: response.error,

0 commit comments

Comments
 (0)