Skip to content

Commit 73f04bb

Browse files
authored
Merge branch 'main' into durabletask-go-workflow-client
2 parents 910e30f + 6dd4349 commit 73f04bb

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

workflow/context.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,16 @@ func (wfc *WorkflowContext) CallChildWorkflow(workflow interface{}, opts ...call
9494
// The value passed to the Await method must be a pointer or can be nil to ignore the returned value.
9595
// Alternatively, tasks can be awaited using the task.WhenAll or task.WhenAny methods, allowing the workflow
9696
// to block and wait for multiple tasks at the same time.
97-
func (wfc *WorkflowContext) CreateTimer(duration time.Duration) task.Task {
97+
func (wfc *WorkflowContext) CreateTimer(duration time.Duration, opts ...createTimerOption) task.Task {
98+
options := new(createTimerOptions)
99+
for _, configure := range opts {
100+
if err := configure(options); err != nil {
101+
return nil
102+
}
103+
}
104+
if options.name != nil {
105+
return wfc.orchestrationContext.CreateTimer(duration, task.WithTimerName(*options.name))
106+
}
98107
return wfc.orchestrationContext.CreateTimer(duration)
99108
}
100109

workflow/workflow.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,16 @@ func NewTaskSlice(length int) []task.Task {
148148
taskSlice := make([]task.Task, length)
149149
return taskSlice
150150
}
151+
152+
type createTimerOption func(*createTimerOptions) error
153+
154+
type createTimerOptions struct {
155+
name *string
156+
}
157+
158+
func WithTimerName(name string) createTimerOption {
159+
return func(opt *createTimerOptions) error {
160+
opt.name = &name
161+
return nil
162+
}
163+
}

workflow/workflow_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
89

910
"github.com/dapr/durabletask-go/api/protos"
1011
"github.com/dapr/durabletask-go/task"
@@ -76,3 +77,21 @@ func TestNewTaskSlice(t *testing.T) {
7677
tasks := NewTaskSlice(10)
7778
assert.Len(t, tasks, 10)
7879
}
80+
81+
func TestCreateTimerOptions(t *testing.T) {
82+
t.Run("create timer options - valid", func(t *testing.T) {
83+
opts := returnCreateTimerOptions(WithTimerName("test"))
84+
require.NotNil(t, opts.name)
85+
require.Equal(t, "test", *opts.name)
86+
})
87+
}
88+
89+
func returnCreateTimerOptions(opts ...createTimerOption) createTimerOptions {
90+
options := new(createTimerOptions)
91+
for _, configure := range opts {
92+
if err := configure(options); err != nil {
93+
return *options
94+
}
95+
}
96+
return *options
97+
}

0 commit comments

Comments
 (0)