I'm writing a slack bot with Go and Aws Lambda. Slack requires for the bot to reply within 3 seconds. However, sometimes I can't make it reply that fast, cuz it's "talking" to other serverless applications for requesting some data or dispatching tasks. I have never worked with goroutines before, but I was hoping that I could implement something like this:
- Lambda receives a request
- The bot creates a goroutine that will process this request and act accordingly on it
- The handler doesn't wait for all these actions to complete but replies right away with 200.
- Lambda continues to run until goroutine is finished.
I'm not sure if that's even possible.
I've read about sync.WaitGroup
, but I'm not sure how to incorporate it together with main function. Should I use it inside the handler? But I need to return
response and that's not a function that I can wrap into a goroutine.
Ideally, I would like for handler to reply right away and then process goroutine in the background.