fsnotify icon indicating copy to clipboard operation
fsnotify copied to clipboard

Write Events/Errors using select

Open howeyc opened this issue 13 years ago • 9 comments

This is a request that came up earlier that I almost forgot about. Creating issue so I remember.

Desire is to have the library send events/errors using select so that the receiving application can be monitoring the channels without the use of a separate goroutine.

howeyc avatar Jun 06 '12 22:06 howeyc

What would this look like? Same channels/API just without requiring a goroutine?

nathany avatar Sep 04 '13 19:09 nathany

Yes. On Sep 4, 2013 12:14 PM, "Nathan Youngman" [email protected] wrote:

What would this look like? Same channels/API just without requiring a goroutine?

— Reply to this email directly or view it on GitHubhttps://github.com/howeyc/fsnotify/issues/7#issuecomment-23815989 .

howeyc avatar Sep 04 '13 23:09 howeyc

Chime in for the os/notify API: http://goo.gl/MrYxyA

nathany avatar Jan 16 '14 05:01 nathany

I'm not sure what makes this single thread unfriendly? Why can't I do something like:

func main() {
  // create watcher
  w.Add("./")
  for {
    select {
      case <-w.Events:
        // do stuff
      case <-w.Errors:
        // handle error
      case <-sig:
        // signal received, probably quit
    }
  }
}

aktau avatar Jul 08 '14 12:07 aktau

See https://code.google.com/p/go/issues/detail?id=8282#c4 for one issue when using code very similar to what you presented.

If you want to take a closer look on multiple platforms, please report your findings at https://github.com/fsnotify/fsnotify/issues/new

nathany avatar Jul 08 '14 14:07 nathany

Right. I suppose this is only an issue on some platforms (old linux? I saw some mentioning of the lowest linux denominator being too low to stop this from happening). Anyway, I'll run it in a separate goroutine for the time being and monitor this space. I'd love to be able to safely use it in single-threaded mode. As it stands, it's not very obvious one needs to do this goroutine trick. Thanks for the update!

aktau avatar Jul 08 '14 15:07 aktau

At GopherCon India last month, Alan Shreve gave a talk on Principles of designing Go APIs with channels which i thought might be relevant for this issue in FSNotify since I too had to puzzle through the sources to check if it's using blocking channels... Specifically An API that sends an unbounded stream of values into a channel must document how it behaves for slow consumers

srinathh avatar Mar 15 '15 02:03 srinathh

@srinathh Thanks for the tip. Now that the videos are up, I'll be sure to watch that talk.

nathany avatar Mar 18 '15 18:03 nathany

Is this still an issue? https://github.com/golang/go/issues/8282#issuecomment-66134528

If so, what would be the non-racey way of doing this?

matthewmueller avatar May 17 '20 16:05 matthewmueller