Can you provide a pattern of how to invoke method async with result? is there any best practice to invoke it by configuration sync/async
The keyword you have to search for is goroutines
Here is one example: https://gobyexample.com/goroutines
If you follow the tutorial, channels, buffered channels and syncronized channels will give you some way to return data.
Example 2: https://tour.golang.org/concurrency/1
Example 3: http://www.golangbootcamp.com/book/concurrency
TL;DR: Here is your pattern:
package main
import "fmt"
func sum(a []int, c chan int) {
sum := 0
for _, v := range a {
sum += v
}
c <- sum // send sum to c
}
func main() {
a := []int{7, 2, 8, -9, 4, 0}
c := make(chan int)
go sum(a[:len(a)/2], c)
go sum(a[len(a)/2:], c)
x, y := <-c, <-c // receive from c
fmt.Println(x, y, x+y)
}