You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package util
import ( "fmt" "testing" "time" )
func TestAsyncPool(t *testing.T) { p := NewLimitedAsyncExecutor(3) var results []Future
results = append(results, p.Execute(FirstFunc)) results = append(results, p.Execute(SecondFunc)) results = append(results, p.Execute(ThirdFunc)) results = append(results, p.Execute(FourthFunc)) results = append(results, p.Execute(FifthFunc))
for _, r := range results { x := r.Await().(int) println(x) } }
func FirstFunc() any { fmt.Println("-- Executing first function --") time.Sleep(7 * time.Second) fmt.Println("-- First Function finished --") return 1 }
func SecondFunc() any { fmt.Println("-- Executing second function --") time.Sleep(5 * time.Second) fmt.Println("-- Second Function finished --") return 2 }
func ThirdFunc() any { fmt.Println("-- Executing third function --") time.Sleep(2 * time.Second) fmt.Println("-- Third Function finished --") return 3 }
func FourthFunc() any { fmt.Println("-- Executing fourth function --") time.Sleep(10 * time.Second) fmt.Println("-- Fourth Function finished --") return 4 }
func FifthFunc() any { fmt.Println("-- Executing fifth function --") time.Sleep(4 * time.Second) fmt.Println("-- Fourth fifth finished --") return 5 }
|