← Concurrent | Asynchronous Call(中文) | Home →
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
-
Use callback to control the callback
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(中文) | Home →