The question originates in: how much work can I do in the background, when the response has already been sent. For instance: I just want to receive data, tell the client 'ok', and proceed with some database operations that may take some time.
package main
import (
"fmt"
"context"
"github.com/aws/aws-lambda-go/lambda"
)
type MyEvent struct {
Name string `json:"name"`
}
func HandleRequest(ctx context.Context, name MyEvent) (string, error) {
go RecordQuery(name)
return fmt.Sprintf("Hello %s!", name.Name ), nil
}
func RecordQuery(name MyEvent) {
// insert stuff in the database, mark user active,
// log activity, etc..
}
func main() {
lambda.Start(HandleRequest)
}
Can we count on the goroutine to be able to do its work?