Skip to content
This repository was archived by the owner on Dec 28, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions coop.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,6 @@ func Every(dur time.Duration, fn func()) {
})
}

// Runs fn and times out if it runs longer than the provided
// duration. It will send false to the returning
// channel if timeout occurs.
// TODO: cancel if timeout occurs
func Timeout(duration time.Duration, fn func()) (done <-chan bool) {
ch := make(chan bool, 2)
go func() {
<-time.After(duration)
doneSig(ch, false)
}()
go func() {
fn()
doneSig(ch, true)
}()
return ch
}

// Starts to run the given list of fns concurrently.
func All(fns ...func()) (done <-chan bool) {
var wg sync.WaitGroup
Expand Down
18 changes: 0 additions & 18 deletions coop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,6 @@ func TestUntil_Past(test *testing.T) {
}
}

func TestTimeout_TimedOut(test *testing.T) {
done := Timeout(100*time.Millisecond, func() {
time.Sleep(time.Minute)
})
if <-done {
test.Errorf("Expected to get timed out, but it has been completed")
}
}

func TestTimeout_Completed(test *testing.T) {
done := Timeout(time.Minute, func() {
time.Sleep(100 * time.Millisecond)
})
if !<-done {
test.Errorf("Expected to get completed, but it has been timed out")
}
}

func TestAll(test *testing.T) {
start := time.Now()
var val1, val2, val3 bool
Expand Down