This file contains hidden or 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
// This is an example of a self-cleaning worker. A common pattern in Go | |
// is to have a type which, when created with NewX, spawns one or more | |
// goroutines in the background to perform work. It is usually the | |
// caller's responsibility to call Close() or Stop() in order to shut | |
// these workers down and not leak goroutines and the memory resources | |
// that the goroutines have references to. | |
// | |
// The idea behind a self-cleaning worker is to leverage the runtime's | |
// ability to set finalizers on objects in order to detect when an object | |
// with a still-live worker goroutine has gone out of scope. The type |