func SignalWorkflow(ctx workflow.Context) error {
logger := workflow.GetLogger(ctx)
requestLockCh := workflow.GetSignalChannel(ctx, "test-signals")
for iterations := 0; iterations < 10; iterations++ { <- here, the logic will give up after 10 batch receive of signals
var n int
for requestLockCh.ReceiveAsync(&n) {
logger.Info("Got signal", "N", n)
}
workflow.Sleep(ctx, time.Second)
}
return workflow.NewContinueAsNewError(ctx, SignalWorkflow)
}
you may want to add additional handling of signals just before return
func SignalWorkflow(ctx workflow.Context) error {
logger := workflow.GetLogger(ctx)
requestLockCh := workflow.GetSignalChannel(ctx, "test-signals")
for iterations := 0; iterations < 10; iterations++ {
var n int
for requestLockCh.ReceiveAsync(&n) {
logger.Info("Got signal", "N", n)
}
workflow.Sleep(ctx, time.Second)
}
var n int <- additional logic
for requestLockCh.ReceiveAsync(&n) {
logger.Info("Got signal", "N", n)
}
return workflow.NewContinueAsNewError(ctx, SignalWorkflow)
}
SDK logs also shows
2020/11/16 14:57:16 INFO Workflow has unhandled signals Namespace default TaskQueue test-queue WorkerID 42150@Chriss-MacBook-Pro.local@ WorkflowType SignalWorkflow WorkflowID test-workflow RunID 79cc26c1-5fa3-420e-b2dd-af18ac6b2cd9 SignalNames [test-signals]