← Concurrent | Asynchronous Call(中文) | Package Management →
Alibaba Cloud Go SDK supports asynchronous calls in two ways:
Using channel as return values
responseChannel, errChannel := client.FooWithChan(request)
// this will block
response := <-responseChannel
err = <-errChannel
blocker := client.FooWithCallback(request, func(response *FooResponse, err error) {
// handle the response and err
})
// blocker which is type of (chan int),is used to control synchronization,when returning 1 means success,and returning 0 means failure.
// When <-blocker returns failure,err also will be handled by afferent callback.
result := <-blocker
← Concurrent | Asynchronous Call(中文) | Package Management →