Skip to content

Commit 9231003

Browse files
committed
Improve documentation for workflow package
1 parent 02f1dd3 commit 9231003

20 files changed

+48
-14
lines changed

internal/workflow/executor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func Test_Executor(t *testing.T) {
282282
sync.Await[int](f1, func(ctx sync.Context, f sync.Future[int]) {
283283
workflowWithSelectorHits++
284284
}),
285-
sync.Await[struct{}](t, func(ctx sync.Context, _ sync.Future[struct{}]) {
285+
sync.Await[any](t, func(ctx sync.Context, _ sync.Future[any]) {
286286
workflowWithSelectorHits++
287287
}),
288288
)

samples/timer/timer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func Workflow1(ctx workflow.Context, msg string) (string, error) {
7373

7474
workflow.Select(
7575
ctx,
76-
workflow.Await(workflow.ScheduleTimer(tctx, 2*time.Second), func(ctx workflow.Context, f workflow.Future[struct{}]) {
76+
workflow.Await(workflow.ScheduleTimer(tctx, 2*time.Second), func(ctx workflow.Context, f workflow.Future[any]) {
7777
if _, err := f.Get(ctx); err != nil {
7878
logger.Debug("Timer canceled")
7979
} else {

tester/tester_activity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func Test_Activity_Long(t *testing.T) {
2424

2525
workflow.Select(ctx,
2626
// Fire timer before `activity1` completes
27-
workflow.Await(workflow.ScheduleTimer(tctx, time.Millisecond*100), func(ctx workflow.Context, f workflow.Future[struct{}]) {
27+
workflow.Await(workflow.ScheduleTimer(tctx, time.Millisecond*100), func(ctx workflow.Context, f workflow.Future[any]) {
2828
// Timer fired
2929
r = "timer"
3030
}),

tester/tester_timers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ func timerCancellationSubWorkflow(ctx workflow.Context) error {
109109

110110
workflow.Select(
111111
ctx,
112-
workflow.Await(t, func(ctx workflow.Context, f workflow.Future[struct{}]) {
112+
workflow.Await(t, func(ctx workflow.Context, _ workflow.Future[any]) {
113113
// Cancel t2
114114
cancel()
115115
}),
116-
workflow.Await(t2, func(ctx workflow.Context, f workflow.Future[struct{}]) {
116+
workflow.Await(t2, func(ctx workflow.Context, _ workflow.Future[any]) {
117117
// do nothing here, should never fire
118118
panic("timer should have been cancelled")
119119
}),

workflow/channel.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@ package workflow
33
import "github.com/cschleiden/go-workflows/internal/sync"
44

55
type Channel[T any] interface {
6+
// Send sends a value to the channel. If the channel is closed, this will panic.
67
Send(ctx Context, v T)
78

9+
// SendNonblocking sends a value to the channel. This call is non-blocking and will return whether the
10+
// value could be sent. If the channel is closed, this will panic
811
SendNonblocking(v T) (ok bool)
912

13+
// Receive receives a value from the channel.
1014
Receive(ctx Context) (v T, ok bool)
1115

16+
// ReceiveNonBlocking tries to receives a value from the channel. This call is non-blocking and will return
17+
// whether the value could be returned.
1218
ReceiveNonBlocking() (v T, ok bool)
1319

20+
// Close closes the channel. This will cause all future send operations to panic.
1421
Close()
1522
}
1623

24+
// NewChannel creates a new channel.
1725
func NewChannel[T any]() Channel[T] {
1826
return sync.NewChannel[T]()
1927
}
2028

29+
// NewBufferedChannel creates a new buffered channel with the given size.
2130
func NewBufferedChannel[T any](size int) Channel[T] {
2231
return sync.NewBufferedChannel[T](size)
2332
}

workflow/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func WithValue(parent Context, key, val interface{}) Context {
3131
return sync.WithValue(parent, key, val)
3232
}
3333

34+
// NewDisconnectedContext creates a new context that is disconnected from any parent
35+
// context.
3436
func NewDisconnectedContext(ctx Context) Context {
3537
return sync.NewDisconnectedContext(ctx)
3638
}

workflow/continueasnew.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/cschleiden/go-workflows/internal/continueasnew"
1010
)
1111

12-
// ContinueAsNew restarts the current workflow with the given arguments
13-
func ContinueAsNew(ctx Context, args ...interface{}) error {
12+
// ContinueAsNew restarts the current workflow with the given arguments.
13+
func ContinueAsNew(ctx Context, args ...any) error {
1414
// Capture context
1515
propagators := propagators(ctx)
1616
metadata := &metadata.WorkflowMetadata{}

workflow/instance.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/cschleiden/go-workflows/internal/workflowstate"
55
)
66

7+
// WorkflowInstance returns the current workflow instance.
78
func WorkflowInstance(ctx Context) *Instance {
89
wfState := workflowstate.WorkflowState(ctx)
910
return wfState.Instance()

workflow/logger.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/cschleiden/go-workflows/internal/workflowstate"
77
)
88

9+
// Logger returns the logger for the current workflow.
910
func Logger(ctx Context) *slog.Logger {
1011
wfState := workflowstate.WorkflowState(ctx)
1112
return wfState.Logger()

workflow/now.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/cschleiden/go-workflows/internal/workflowstate"
77
)
88

9+
// Now returns the current time.
910
func Now(ctx Context) time.Time {
1011
wfState := workflowstate.WorkflowState(ctx)
1112
return wfState.Time()

0 commit comments

Comments
 (0)