cadence-workflow/cadence-go-client

Add Channel.ReceiveWithTimeout

Closed this issue · 1 comments

Add convinience method

ReceiveWithTimeout(ctx Context, timeout time.Duration, valuePtr interface{}) (timedOut, more bool)

This would make this frequently used code:

sigCh := workflow.GetSignalChannel(ctx, "signal1")
timeout := workflow.NewTimer(ctx, time.Minute * 30)
var signal *SignalStruct

s := workflow.NewSelector(ctx)
s.AddFuture(timeout, func(f Future) {
})
s.AddReceive(sigCh, func(c Channel, more bool) {
    c.Receive(ctx, signal)
})
s.Select(ctx)

into

sigCh := workflow.GetSignalChannel(ctx, "signal1")
var signal *SignalStruct
sigCh.ReceiveWithTimeout(ctx, time.Minute * 30, signal)

Hi, How about the Channel.Receive, it will be canceled automatically after the workflow timeout?