Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API #4

Open
kolmodin opened this issue Nov 6, 2012 · 9 comments
Open

New API #4

kolmodin opened this issue Nov 6, 2012 · 9 comments

Comments

@kolmodin
Copy link
Owner

kolmodin commented Nov 6, 2012

Thinking of a new API for version 0.4.

The current callback based API has several weaknesses, including silently dropping exceptions from the user's callback code which several users has noticed.

A new API could look something like this:

inotify :: IO INotify
addInotify :: INotify -> [EventVariety] -> FilePath -> IO WatchDescriptor
readEvents :: INotify -> IO [Event]

It'd be without background threads, without channels, thus much simpler.
Event overflow would be left to the linux kernel.

@ChristopherKing42
Copy link

The problem is this requires polling in the client application. STM based queues would give you the best of both worlds (although adds more dependencies).

@kolmodin
Copy link
Owner Author

The application can solve it in whatever way it wishes if we provide the building blocks.

@ChristopherKing42
Copy link

One other building block I would add is waitForEvent :: INotify -> IO Event. This way instead of an application repeatedly calling readEvent waiting for a new Event to pop up (which would both consume unnecessary resources and be slower) they could just call waitForEvent to, well, wait for an Event.

(Actually, if we want to go for minimalism, all you need is waitForEvent :: INotify -> IO Event and noBlockEvent :: INotify -> Maybe Event (and define readEvents in terms of it) (and you need inotify and addInotify of course).)

A lot of different concurrency mechanisms (Async, STM, etc...) would benefit from this addition.

@kolmodin
Copy link
Owner Author

It wouldn't be efficient to only read a single event. For performance reasons they should be read in batch. It's also essential to wait until there is enough events to read. More details here; http://www.serpentine.com/blog/2008/01/04/why-you-should-not-use-pyinotify/

@ChristopherKing42
Copy link

Well, some sort of blocking call would be useful. Maybe waitFotEvents :: INotify -> n -> [Event]? Or have a cache of events, and waitEvent just takes off the top event (if available).

@kolmodin
Copy link
Owner Author

Looks like you're describing readEvents in the top post.

@ChristopherKing42
Copy link

Does readEvents block until events are ready, or does it return the empty list if there are no events?

@kolmodin
Copy link
Owner Author

At least on Linux it'd block until something is available, and then return that.
It won't be a lot, which is why there should be a threshold before reading.

@ChristopherKing42
Copy link

Ah, okay. (Then I would recommend making a nonblocking version of readEvents. Note that readEventsNoBlock would still wait for thresholds and such, it just that if there aren't events (either because there really are no events, or because we do not want to check for them yet), it yields [].) It would be more efficient to put this in the library I think than to make the user check for it.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants