Go SDK - Sequential by ID otherwise in parallel

There is no need to use Selector if you are reading from a single channel. Channel.Receive already blocks if a channel is empty. I would rewrite this code as:

	signalChan := workflow.GetSignalChannel(ctx, signalName)

	for i := 0; i < CONTINUE_AS_NEW_FREQUENCY; i++ {
		var signalVal string
		signalChan.Receive(ctx, &signalVal)
		workflow.GetLogger(ctx).Info("Received signal!", "signal", signalName, "value", signalVal)
		// PROCESS SIGNAL
	}
	// Drain signal channel asynchronously to avoid signal loss
	for {
		var signalVal string
		ok := signalChan.ReceiveAsync(&signalVal)
		if !ok {
			break;
		}
		workflow.GetLogger(ctx).Info("Received signal!", "signal", signalName, "value", signalVal)
		// PROCESS SIGNAL
	}
	return workflow.NewContinueAsNewError(ctx, WorkflowFn)
1 Like