Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.74 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "os"
  5.     "path/filepath"
  6.     "time"
  7. )
  8.  
  9. const NUM_WORKERS = 5
  10.  
  11. var sourceFileChan = make(chan SourceFile)
  12.  
  13. type SourceFile struct {
  14.     Path     string
  15.     Date     string
  16.     PresetID int
  17. }
  18.  
  19. func listFunc(path string, file os.FileInfo, err error) error {
  20.     if err != nil {
  21.         println("ERROR BLYA", err.Error())
  22.     }
  23.     source := SourceFile{Path: path}
  24.     sourceFileChan <- source
  25.     return nil
  26. }
  27. func converter() {
  28.     for conv := range sourceFileChan {
  29.         println("Имитация бурной деятельности ", conv.Path)
  30.         time.Sleep(5 * time.Second)
  31.     }
  32. }
  33.  
  34. func main() {
  35.     for i := 0; i < NUM_WORKERS; i++ {
  36.         go converter()
  37.     }
  38.     for {
  39.         filepath.Walk(os.Args[1], listFunc)
  40.         time.Sleep(1 * time.Second)
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement