mirror of
https://github.com/coder/coder.git
synced 2025-03-14 10:09:57 +00:00
24 lines
381 B
Go
24 lines
381 B
Go
package testutil
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// Go runs fn in a goroutine and waits until fn has completed before
|
|
// test completion. Done is returned for optionally waiting for fn to
|
|
// exit.
|
|
func Go(t *testing.T, fn func()) (done <-chan struct{}) {
|
|
t.Helper()
|
|
|
|
doneC := make(chan struct{})
|
|
t.Cleanup(func() {
|
|
<-doneC
|
|
})
|
|
go func() {
|
|
fn()
|
|
close(doneC)
|
|
}()
|
|
|
|
return doneC
|
|
}
|