title: Hotfolder in Go / wait for file to be written
body: <p>I am trying to setup a directory as a hotfolder in Go. As soon as a file is finished written to that directory, a function should get called.</p>
  
  <p>Now I came across <a href="https://github.com/howeyc/fsnotify" rel="noreferrer">https://github.com/howeyc/fsnotify</a> that seems to be a good building block for such a hotfolder. </p>
  
  <p>My problem is that fsnotify emits lots of "file changed" events during the write but none when finished, so I assume its not possible that way to see if a process has finished writing files. </p>
  
  <p>So I would think of "wait one second after the last 'file changed' event and then run my function. But I am unsure if this is the best way to deal with the problem and I am not really sure how to integrate this cleanly in the main event loop (from the given github page):</p>
  
  <pre><code>for {
      select {
      case ev := &lt;-watcher.Event:
          log.Println("event:", ev)
      case err := &lt;-watcher.Error:
          log.Println("error:", err)
      }
  }
  </code></pre>
  
  <p>Any idea / advise?</p>