Last active
April 30, 2016 17:18
-
-
Save brnstz/5bc7083e7a07252a94fa42d4c002aa88 to your computer and use it in GitHub Desktop.
wikimg firstcolor cancel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (p *Puller) FirstColor(imgURL string) (xtermColor int, hex string, err error) { | |
// etc... | |
rect := img.Bounds() | |
i := 0 | |
for x := 0; x < rect.Dx(); x++ { | |
for y := 0; y < rect.Dy(); y++ { | |
// Check if p.Cancel has been closed once every cancelCheckpoint | |
// iterations | |
if i%cancelCheckpoint == 0 { | |
select { | |
case <-p.Cancel: | |
// If p.Cancel has been closed, this will be triggered | |
err = Canceled | |
return | |
default: | |
// Otherwise we'll just do nothing immediately | |
} | |
} | |
i++ | |
// etc... | |
} | |
} | |
// etc... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment