Skip to content

Progress meter implemented as an io.Reader with channels

Notifications You must be signed in to change notification settings

box-builder/progress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Package progress - progress meters through a channel, wrapping an io.Reader

Build Status GoDoc

Example:

func progress(reader io.Reader) {
	r = NewReader("an_file.tar", reader, 100*time.Millisecond)
	defer r.Close()

	var count uint64
	// This goroutine consumes the channel and concatenates the count to display
	// the total as it increases.
	go func(r *Reader) {
		for tick := range r.C {
			count += tick.Value
			fmt.Printf("\r%d", count)
		}

		fmt.Println()
	}(r)

	// use r like you normally would; progress will be reported to C every 100
	// milliseconds.
	if _, err := io.Copy(ioutil.Discard, r); err != nil {
		panic(err)
	}
}

Author

Erik Hollensbe github@hollensbe.org

About

Progress meter implemented as an io.Reader with channels

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages