Yes, the question is set too broadly, it is necessary to specify the 
context, 
thank you.

четверг, 6 июля 2023 г. в 02:33:18 UTC+3, ben...@gmail.com: 

> For simple things, you can fire up a goroutine to do the "something else" 
> after the request finishes. For example, I've used this before to kick off 
> sending an email to a customer in the background (you'll want to 
> handle/report errors somehow though):
>
> package main
>
> import (
> "fmt"
> "log"
> "net/http"
> "time"
> )
>
> func main() {
> http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
> fmt.Fprint(w, "sending email in the background")
> go sendEmail()
> // response is sent, but sendEmail goroutine continues
> })
> log.Print("listening on http://localhost:8080";)
> http.ListenAndServe(":8080", nil)
> }
>
> func sendEmail() {
> log.Printf("would send an email here")
> time.Sleep(time.Second)
> log.Printf("done sending email")
> }
>
> On Thursday, July 6, 2023 at 2:03:47 AM UTC+12 alex-coder wrote:
>
> Hi All !
>
> So, http server looks like is a request / response processing.
> But in case it is nesessary to do something else after the response has 
> been sent to the client, how to do it properly ?
> Is there any example to read ?
>
> Thank you.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e8d9e2db-7c10-4d14-aee7-3a1625f1c22an%40googlegroups.com.

Reply via email to