howeyc/fsnotify

Separate goroutine?

Closed this issue · 7 comments

In your readme you say: Do I have to watch the Error and Event channels in a separate goroutine?
As of now, yes. Looking into making this single-thread friendly.

But the example code right above it only runs a single goroutine:

go func() {
    for {
        select {
        case ev := <-watcher.Event:
            log.Println("event:", ev)
        case err := <-watcher.Error:
            log.Println("error:", err)
        }
    }
}()

What gives?

Oh, what I meant was that you'd need to read the events from the channels in a goroutine, not that you needed a separate goroutine per channel.

What I was really getting at was you can't create a watch then block on the channel and not expect a deadlock. Am I making sense? Any ideas how I can make it more clear in the readme?

It's not very clear :-( I am a Go noob.

On Thu, Apr 4, 2013 at 5:18 PM, Chris Howey notifications@github.comwrote:

Oh, what I meant was that you'd need to read the events from the channels
in a goroutine, not that you needed a separate goroutine per channel.

What I was really getting at was you can't create a watch then block on
the channel and not expect a deadlock. Am I making sense? Any ideas how I
can make it more clear in the readme?


Reply to this email directly or view it on GitHubhttps://github.com//issues/38#issuecomment-15932275
.

Basically if you try to use this library without at least one goroutine to process the channels it will not work.

Ah. That is reasonable. What would be the improvement?
On Apr 4, 2013 8:11 PM, "Chris Howey" notifications@github.com wrote:

Basically if you try to use this library without at least one goroutine to
process the channels it will not work.


Reply to this email directly or view it on GitHubhttps://github.com//issues/38#issuecomment-15937024
.

The improvement would be allowing it to be used without the need to create any goroutines. There was some requests for this earlier on, but the change is not trivial (as far as I can tell), and I'm not sure the benefit. So it's kind of just sat there as something to eventually do.

At this point I'm not sure if I'll ever do it.

I am using your code as is, and it works very well. Thanks!!!!
On Apr 4, 2013 8:57 PM, "Chris Howey" notifications@github.com wrote:

The improvement would be allowing it to be used without the need to create
any goroutines. There was some requests for this earlier on, but the change
is not trivial (as far as I can tell), and I'm not sure the benefit. So
it's kind of just sat there as something to eventually do.

At this point I'm not sure if I'll ever do it.


Reply to this email directly or view it on GitHubhttps://github.com//issues/38#issuecomment-15937894
.

A goroutine uses select to monitor the watcher channels.
Should the select NOT include other channels from my program?
Should the watcher channels have their own goroutine and my other channels in another goroutine?