1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-22 15:22:51 +03:00
lazygit/pkg/tasks/async_handler_test.go
Stefan Haller 1869fda800 Make OnWorker callback return an error
This lets us get rid of a few more calls to Error(), and it simplifies things
for clients of OnWorker: they can simply return an error from their callback
like we do everywhere else.
2024-04-18 10:10:30 +02:00

49 lines
716 B
Go

package tasks
import (
"fmt"
"sync"
"testing"
"github.com/jesseduffield/gocui"
"github.com/stretchr/testify/assert"
)
func TestAsyncHandler(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(2)
onWorker := func(f func(gocui.Task) error) {
go func() { _ = f(gocui.NewFakeTask()) }()
}
handler := NewAsyncHandler(onWorker)
handler.onReject = func() {
wg.Done()
}
result := 0
wg2 := sync.WaitGroup{}
wg2.Add(1)
handler.Do(func() func() {
wg2.Wait()
return func() {
fmt.Println("setting to 1")
result = 1
}
})
handler.Do(func() func() {
return func() {
fmt.Println("setting to 2")
result = 2
wg.Done()
wg2.Done()
}
})
wg.Wait()
assert.EqualValues(t, 2, result)
}