Use case of sub process and sample logic to use

Hi all recently
we use selector to determine which flow to executed
now we have flow like this

we know how to make the process inside the sub process
but for the sub process part any idea what should we use from temporal feature

for !signalReceive && ctx.Err() == nil {
		selector := workflow.NewSelector(ctx)
		threeHourTimer := workflow.NewTimer(ctx, threeHour)
		selector.AddFuture(threeHourTimer, func(f workflow.Future) {
			err1 := f.Get(ctx, nil)
			if err1 == nil {
			} else if ctx.Err() != nil {
				logger.Error("Error occurred.", "error", ctx.Err())
		selector.AddReceive(workflow.GetSignalChannel(ctx, SignalAction),
			func(c workflow.ReceiveChannel, more bool) {
				c.Receive(ctx, &request)

how do we make the sub process ?

  1. future action for timer 2 days, and only executed if inside sub process aren’t done within 2 days

I would use a goroutine to implement your subprocess. Something like:

	subprocessDone := false
	workflow.Go(ctx, func(ctx workflow.Context) {
		signal := workflow.GetSignalChannel(ctx, "actionSignal")
		for {
			ok, more := signal.ReceiveWithTimeout(ctx, 3*time.Hour, &request)
			if ok {

			} else {
				// timed out
		subprocessDone = true

	workflow.AwaitWithTimeout(ctx, 48*time.Hour, func() bool {
		return subprocessDone

I would also recommend using Channel.ReceiveWithTimeout instead of the selector to listen on a single signal channel.

1 Like

Thank You Maxim for the suggestion
We’ll try this