Skip to content

Commit a0c3ad2

Browse files
committed
Use type alias where possible
1 parent 477028a commit a0c3ad2

File tree

11 files changed

+18
-21
lines changed

11 files changed

+18
-21
lines changed

workflow/activity.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var DefaultActivityOptions = ActivityOptions{
2727

2828
// ExecuteActivity schedules the given activity to be executed
2929
func ExecuteActivity[TResult any](ctx Context, options ActivityOptions, activity interface{}, args ...interface{}) Future[TResult] {
30-
return WithRetries(ctx, options.RetryOptions, func(ctx sync.Context, attempt int) Future[TResult] {
30+
return WithRetries(ctx, options.RetryOptions, func(ctx Context, attempt int) Future[TResult] {
3131
return executeActivity[TResult](ctx, options, attempt, activity, args...)
3232
})
3333
}
@@ -93,7 +93,7 @@ func executeActivity[TResult any](ctx Context, options ActivityOptions, attempt
9393
if cmd.State() == command.CommandState_Pending {
9494
cmd.Done()
9595
wfState.RemoveFuture(scheduleEventID)
96-
f.Set(*new(TResult), sync.Canceled)
96+
f.Set(*new(TResult), Canceled)
9797
}
9898
}
9999
}

workflow/activity_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Test_executeActivity_ResultMismatch(t *testing.T) {
2828
)
2929
ctx = workflowtracer.WithWorkflowTracer(ctx, workflowtracer.New(trace.NewNoopTracerProvider().Tracer("test")))
3030

31-
c := sync.NewCoroutine(ctx, func(ctx sync.Context) error {
31+
c := sync.NewCoroutine(ctx, func(ctx Context) error {
3232
f := executeActivity[string](ctx, DefaultActivityOptions, 1, a)
3333
_, err := f.Get(ctx)
3434
require.Error(t, err)
@@ -52,7 +52,7 @@ func Test_executeActivity_ParamMismatch(t *testing.T) {
5252
)
5353
ctx = workflowtracer.WithWorkflowTracer(ctx, workflowtracer.New(trace.NewNoopTracerProvider().Tracer("test")))
5454

55-
c := sync.NewCoroutine(ctx, func(ctx sync.Context) error {
55+
c := sync.NewCoroutine(ctx, func(ctx Context) error {
5656
f := executeActivity[int](ctx, DefaultActivityOptions, 1, a)
5757
_, err := f.Get(ctx)
5858
require.Error(t, err)

workflow/instance.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package workflow
22

33
import (
4-
"github.com/cschleiden/go-workflows/internal/sync"
54
"github.com/cschleiden/go-workflows/internal/workflowstate"
65
)
76

8-
func WorkflowInstance(ctx sync.Context) *Instance {
7+
func WorkflowInstance(ctx Context) *Instance {
98
wfState := workflowstate.WorkflowState(ctx)
109
return wfState.Instance()
1110
}

workflow/now.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package workflow
33
import (
44
"time"
55

6-
"github.com/cschleiden/go-workflows/internal/sync"
76
"github.com/cschleiden/go-workflows/internal/workflowstate"
87
)
98

10-
func Now(ctx sync.Context) time.Time {
9+
func Now(ctx Context) time.Time {
1110
wfState := workflowstate.WorkflowState(ctx)
1211
return wfState.Time()
1312
}

workflow/retries.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func WithRetries[T any](ctx Context, retryOptions RetryOptions, fn func(ctx Cont
4444
// Start a separate co-routine for retries
4545
r := sync.NewFuture[T]()
4646

47-
Go(ctx, func(ctx sync.Context) {
47+
Go(ctx, func(ctx Context) {
4848
var result T
4949
var err error
5050

workflow/sleep.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ package workflow
33
import (
44
"time"
55

6-
"github.com/cschleiden/go-workflows/internal/sync"
76
"github.com/cschleiden/go-workflows/internal/workflowtracer"
87
"github.com/cschleiden/go-workflows/log"
98
"go.opentelemetry.io/otel/attribute"
109
"go.opentelemetry.io/otel/trace"
1110
)
1211

13-
func Sleep(ctx sync.Context, d time.Duration) error {
12+
func Sleep(ctx Context, d time.Duration) error {
1413
ctx, span := workflowtracer.Tracer(ctx).Start(ctx, "Sleep",
1514
trace.WithAttributes(attribute.Int64(log.DurationKey, int64(d/time.Millisecond))))
1615
defer span.End()

workflow/sleep_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func Test_Sleep_Yields(t *testing.T) {
1212
ctx := sync.Background()
1313

14-
c := sync.NewCoroutine(ctx, func(ctx sync.Context) error {
14+
c := sync.NewCoroutine(ctx, func(ctx Context) error {
1515
Sleep(ctx, 2*time.Millisecond)
1616
require.FailNow(t, "should not reach this")
1717

workflow/subworkflow.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ var (
3434
}
3535
)
3636

37-
func CreateSubWorkflowInstance[TResult any](ctx sync.Context, options SubWorkflowOptions, workflow interface{}, args ...interface{}) Future[TResult] {
38-
return WithRetries(ctx, options.RetryOptions, func(ctx sync.Context, attempt int) Future[TResult] {
37+
func CreateSubWorkflowInstance[TResult any](ctx Context, options SubWorkflowOptions, workflow interface{}, args ...interface{}) Future[TResult] {
38+
return WithRetries(ctx, options.RetryOptions, func(ctx Context, attempt int) Future[TResult] {
3939
return createSubWorkflowInstance[TResult](ctx, options, attempt, workflow, args...)
4040
})
4141
}
4242

43-
func createSubWorkflowInstance[TResult any](ctx sync.Context, options SubWorkflowOptions, attempt int, wf interface{}, args ...interface{}) Future[TResult] {
43+
func createSubWorkflowInstance[TResult any](ctx Context, options SubWorkflowOptions, attempt int, wf interface{}, args ...interface{}) Future[TResult] {
4444
f := sync.NewFuture[TResult]()
4545

4646
// If the context is already canceled, return immediately.
@@ -105,7 +105,7 @@ func createSubWorkflowInstance[TResult any](ctx sync.Context, options SubWorkflo
105105
if fi, ok := f.(sync.FutureInternal[TResult]); ok {
106106
if !fi.Ready() {
107107
wfState.RemoveFuture(scheduleEventID)
108-
f.Set(*new(TResult), sync.Canceled)
108+
f.Set(*new(TResult), Canceled)
109109
}
110110
}
111111
}

workflow/subworkflow_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func Test_createSubWorkflowInstance_ParamMismatch(t *testing.T) {
2828
)
2929
ctx = workflowtracer.WithWorkflowTracer(ctx, workflowtracer.New(trace.NewNoopTracerProvider().Tracer("test")))
3030

31-
c := sync.NewCoroutine(ctx, func(ctx sync.Context) error {
31+
c := sync.NewCoroutine(ctx, func(ctx Context) error {
3232
f := createSubWorkflowInstance[int](ctx, DefaultSubWorkflowOptions, 1, wf, "foo")
3333
_, err := f.Get(ctx)
3434
require.Error(t, err)
@@ -53,7 +53,7 @@ func Test_createSubWorkflowInstance_ReturnMismatch(t *testing.T) {
5353
)
5454
ctx = workflowtracer.WithWorkflowTracer(ctx, workflowtracer.New(trace.NewNoopTracerProvider().Tracer("test")))
5555

56-
c := sync.NewCoroutine(ctx, func(ctx sync.Context) error {
56+
c := sync.NewCoroutine(ctx, func(ctx Context) error {
5757
f := createSubWorkflowInstance[string](ctx, DefaultSubWorkflowOptions, 1, wf)
5858
_, err := f.Get(ctx)
5959
require.Error(t, err)

workflow/timer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func ScheduleTimer(ctx Context, delay time.Duration) Future[struct{}] {
4141
if fi, ok := f.(sync.FutureInternal[struct{}]); ok {
4242
if !fi.Ready() {
4343
wfState.RemoveFuture(scheduleEventID)
44-
f.Set(v, sync.Canceled)
44+
f.Set(v, Canceled)
4545
}
4646
}
4747
},

0 commit comments

Comments
 (0)