go func() {
log.Println("something")
}()
}
can we understand that goroutine in previous loop step done its job ??
in other words can we synchronize these goroutines that are in a loop ??
no. This code will ultimately crash your system. You'll run out of memory fast
what do you mean by synchronize? Make them be called serially? If so, then why do you need those goroutines in the first place?
not this code exactly , imagine the loop is finite
yeah serially , my project is a webrtc sfu and in a loop I will send rtp packets to clients and after that I will write them to a file in disk but this i/o task is time consuming , I don't want that sending rtp packets directly to clients have lags and delay because of this I want to this saving to disk task be run on other goroutine(s)
is a goroutine pool what you're looking for? or do you want to execute N simultaneous tasks and wait for all of them to finish?
emm...I don't know exactly I don't think goroutine pool help me and sync.waitGroup also wont help me
I still don't understand your problem. Why do you want goroutines to execute serially one after another? Can't you just do that in 1 goroutine?
so you have N connections you want to write 1 packet to each of the N connections and resume once all of them are written, right?
I think saving incoming video packets (parts) in disk should be serially right ?? :)
no not resume , first part of what you said is right but this part is not the problem in that loop that I said after I sent for example packet X to clients then I will append that to recording file but this task is time consuming (assume that we don't have nvme disk :) )
var packet []byte for _, c := range connections { c.Send(packet) } file.Write(packet) is this your business logic (simplified)?
here is the code , sorry
Обсуждают сегодня