1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2026-05-22 10:15:43 +02:00
Files
lazygit/pkg/tasks/async_handler_test.go
T
Stefan Haller 196e0a3c17 Copy gocui files into lazygit repo under pkg/gocui
I copied all files except dot files (.github and .gitignore), the _examples
folder, and go.mod/go.sum.

At some point we may want to copy the files back to the gocui repo when other
clients (e.g. lazydocker) want to use the newer versions of them.
2026-04-30 14:29:08 +02:00

49 lines
728 B
Go

package tasks
import (
"fmt"
"sync"
"testing"
"github.com/jesseduffield/lazygit/pkg/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)
}