Files
lo/concurrency_test.go
CorentinClabaut 5debabe433 Implements Async
closes #85
2022-04-04 12:11:34 +02:00

29 lines
372 B
Go

package lo
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAsync(t *testing.T) {
is := assert.New(t)
sync := make(chan struct{})
ch := Async(func() int {
<-sync
return 10
})
sync <- struct{}{}
select {
case result := <-ch:
is.Equal(result, 10)
case <-time.After(time.Millisecond):
is.Fail("Async should not block")
}
}