Implementing asynchronous signal handling

Hello!
I’m looking for more information about how to use signals in my temporal programs. Right now I’m trying to modify this example project to allow the workflow to be interrupted by a signal while it is waiting on the API to respond with a “SUCCESS” or “REJECT” response.

I am currently a computer engineering student and intern and my familiarity with signals comes from Linux/Unix signals so there may be some knowledge gaps on my end, but I am hoping to implement signals in an asynchronous manner like said Unix signals.

A couple things that I’ve tried are using a selector to register a handler that is called when the signal is received but I can’t get this to work without blocking with a statement like selector.Select(). After browsing some of the questions on here I’ve seen that using a selector might not be the way to go for me but I’m not sure how to add a handler to a signal without it.

selector := workflow.NewSelector(ctx)
selector.AddReceive(signalChan, func (c workflow.ReceiveChannel, _ bool){
c.Receive(ctx, &signal)
fmt.Println(“Workflow was signaled”)
})

Using the method above I am able to synchronously use signals but I need to be able to use them asynchronously.

How can I implement and use signals with temporal asynchronously while using the Go-SDK?

Thanks!

The Go approach is to use goroutines for asynchronous code. See await-signals example.

1 Like