Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ func main() {
upload, _ := tus.NewUploadFromFile(f)

// create the uploader.
uploader, _ := client.CreateUpload(upload)
uploader, err := client.CreateUpload(upload)
if err != nil {
panic(err)
}
defer uploader.Close()

// start the uploading process.
uploader.Upload()
Expand Down Expand Up @@ -106,8 +110,10 @@ func main() {
fmt.Println("Error", err)
fmt.Println("Trying again in 10 seg")
time.Sleep(time.Second * 10)
uploader.Close()
continue
}
uploader.Close()
break
}
// If after all attemps there's an error panic!
Expand Down
5 changes: 5 additions & 0 deletions uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func (u *Uploader) UploadChunck() error {
return nil
}

// Close close the notifyChan so that broadcastProgress goroutine can exit
func (u *Uploader) Close() {
close(u.notifyChan)
}

// Waits for a signal to broadcast to all subscribers
func (u *Uploader) broadcastProgress() {
for _ = range u.notifyChan {
Expand Down