Closed HarryL5004 closed 4 years ago
What happened to using WaitGroup?
If waitgroup is used in cmd main.go
, the waitgroup counter can go negative and panic.
Why would we need one in main.go? The issue just concerns the test function.
That's because a wait group instance must be passed into the contract handler to signal the waitgroup that this goroutine is done, and main.go initiate a contract handler.
Hm. Can you do something like
var waitgroup sync.WaitGroup
waitgroup.Add(1)
go func(){
handler.ServeHTTP(rr, tt.req)
waitgroup.Done()
}()
waitgroup.Wait()
I don't think it's a great idea to edit so many files for this issue, I'd almost rather just have the 1 second sleep at that point. But there's gotta be a way to use a WaitGroup to achieve this.
Interesting, do you know why increasing the cap makes it work? I'm curious
Previously the channel blocks all processes until there's a receiver retrieving the contract in the channel. By increasing the capacity, the channel will only start to block processes when it is full. If the channel is never full, it will never block any processes.
Issue #325