March 2019
Intermediate to advanced
336 pages
9h 9m
English
The software program that connects to resources can be set with timeouts. Channels are used for implementing timeouts. You can configure a channel with a timeout interval as follows:
//main package has examples shown// in Go Data Structures and algorithms bookpackage main// importing errors, log and time packagesimport ( "errors" "log" "time")// delayTimeOut methodfunc delayTimeOut(channel chan interface{}, timeOut time.Duration) (interface{}, error) { log.Printf("delayTimeOut enter") defer log.Printf("delayTimeOut exit") var data interface{} select { case <-time.After(timeOut): return nil, errors.New("delayTimeOut time out") case data = <-channel: return data, nil }}//main methodfunc main() { channel ...Read now
Unlock full access