Skip to content

Instantly share code, notes, and snippets.

@brnstz
Last active April 30, 2016 17:18
Show Gist options
  • Save brnstz/5bc7083e7a07252a94fa42d4c002aa88 to your computer and use it in GitHub Desktop.
Save brnstz/5bc7083e7a07252a94fa42d4c002aa88 to your computer and use it in GitHub Desktop.
wikimg firstcolor cancel
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