fx_test.go 518 B

123456789101112131415161718192021222324252627282930313233
  1. package main
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/tal-tech/go-zero/core/fx"
  6. )
  7. func TestFxSplit(t *testing.T) {
  8. fx.Just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).Split(4).ForEach(func(item interface{}) {
  9. vals := item.([]interface{})
  10. fmt.Println(len(vals))
  11. })
  12. }
  13. func BenchmarkFx(b *testing.B) {
  14. type Mixed struct {
  15. Name string
  16. Age int
  17. Gender int
  18. }
  19. for i := 0; i < b.N; i++ {
  20. var mx Mixed
  21. fx.Parallel(func() {
  22. mx.Name = "hello"
  23. }, func() {
  24. mx.Age = 20
  25. }, func() {
  26. mx.Gender = 1
  27. })
  28. }
  29. }