Answer the question
In order to leave comments, you need to log in
Doesn't return JSON when using goroutine?
Good afternoon.
Tell me, I can’t get an error in JSON if I send all the construction
code to a single goroutine for processing
func() {
err := add_user(name,pass)
if err != nil {
jsresponce, _ := json.Marshal(Error{" User "+name+" is already exist !!!! "})
io.WriteString(w, string(jsresponce))
return
}
}()
go func() {
err := add_user(name,pass)
if err != nil {
jsresponce, _ := json.Marshal(Error{" User "+name+" is already exist !!!! "})
io.WriteString(w, string(jsresponce))
return
}
}()
Answer the question
In order to leave comments, you need to log in
Because you don't wait for the goroutine to complete, you exit the json_directory function before the goroutine finishes running. Accordingly, you do not have time to see the result.
In your situation, I don’t see the point of putting it in a goroutine at all. You still have to wait for completion to show the answer, so you can just leave it as the first option.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question