shared/cancel/canceler.go
func CancelableDownload(c *Canceler, client *http.Client, req *http.Request) (*http.Response, chan bool, error) {
	chDone := make(chan bool)
	chCancel := make(chan struct{})
	if c != nil {
		c.lock.Lock()
		c.reqChCancel[req] = chCancel
		c.lock.Unlock()
	}
	req.Cancel = chCancel

	go func() {
		<-chDone
		if c != nil {
			c.lock.Lock()
			delete(c.reqChCancel, req)
			c.lock.Unlock()
		}
	}()

	resp, err := client.Do(req)
	return resp, chDone, err
}
func CancelableDownload(c *Canceler, client *http.Client, req *http.Request) (*http.Response, chan bool, error) {
	chDone := make(chan bool)
	chCancel := make(chan struct{})
	if c != nil {
		c.lock.Lock()
		c.reqChCancel[req] = chCancel
		c.lock.Unlock()
	}
	req.Cancel = chCancel

	go func() {
		<-chDone
		if c != nil {
			c.lock.Lock()
			delete(c.reqChCancel, req)
			c.lock.Unlock()
		}
	}()

	resp, err := client.Do(req)
	return resp, chDone, err
}
func CancelableDownload ( c * Canceler , client * http . Client , req * http . Request ) ( * http . Response , chan bool , error ) { chDone := make ( chan bool ) chCancel := make ( chan struct { } ) if c != nil { c . lock . Lock ( ) c . reqChCancel [ req ] = chCancel c . lock . Unlock ( ) } req . Cancel = chCancel go func ( ) { <- chDone if c != nil { c . lock . Lock ( ) delete ( c . reqChCancel , req ) c . lock . Unlock ( ) } } ( ) resp , err := client . Do ( req ) return resp , chDone , err }
// CancelableDownload performs an http request and allows for it to be canceled at any time
CancelableDownload performs an http request and allows for it to be canceled at any time