Skip to content

Instantly share code, notes, and snippets.

@jimtla
Created August 21, 2014 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimtla/6693f7614ecfcd5fa7e9 to your computer and use it in GitHub Desktop.
Save jimtla/6693f7614ecfcd5fa7e9 to your computer and use it in GitHub Desktop.
Code Sample for Go Leaks blog post
func createAlternateSizes(photoPath string, img image.Image, block bool) error {
// Put a white background on all the resized images.
whiteImg := imageWithWhiteBg(img)
numberOfResizes := 3
c := make(chan error, numberOfResizes)
go resizeAndWrite(whiteImg, 640, photoPath + "_f", c)
go resizeAndWrite(whiteImg, 290, photoPath + "_s", c)
go resizeAndWrite(whiteImg, 200, photoPath + "_d", c)
if block {
// Wait for three things to come back on the channel.
for i := 0; i < numberOfResizes; i++ {
err = <-c
if err != nil {
s.Printf("ERR: %v", err)
return err
}
}
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment