Giter Club home page Giter Club logo

Comments (4)

pyrmont avatar pyrmont commented on June 23, 2024 1

@subsetpark OK, so I rewrote the whole thing as a cleanly separated C library and Janet wrapper. The Janet wrapper no longer uses the thread module and instead does everything on the event loop. Basic functionality appears to work but I don't have a comprehensive test suite at this point. I also haven't written documentation yet, unfortunately.

In case you wanted to play around with it, the idea now is that there are two ways to interact with the library, the easy way and the hard way:

  • Easy: watchful/watch takes a path to watch, a function to call on changes and some (optional) options. The call to watchful/watch returns a fiber. If the consumer wants to stop the watch cleanly, they call watchful/cancel on the fiber.

  • Hard: watchful/monitor will create a monitor object for a path with some (optional) options. The consumer can then use watchful/start and watchful/stop with the monitor object to start and stop the monitor manually. A call to watchful/start returns a channel. Events that are detected by the monitor are created as Janet structs and placed into the channel.

Although the Janet wrapper runs on the event loop, the C library still uses a separate thread to do the monitoring itself. When an event is detected by that monitoring thread, the thread calls a callback that was provided when the monitor was created (together with some user-specified data that was also provided when the monitor was created). The callback defined by the Janet wrapper serialises the pertinent information about the event into a pipe that the watchful module is monitoring on the main thread via the Janet event loop. When the main thread receives the data through the pipe, it transforms it into the Janet struct and puts it into the channel. As Rube Golberg-esque as that might sound, I think this approach is preferable to what I was doing before.

Oh, and it still only provides inotify and FSEvents backends. I would like at some point for there to be ReadDirectoryChangesW and kqueue backends but I want to be more confident the general approach is sound before attempting that.

from watchful.

pyrmont avatar pyrmont commented on June 23, 2024

Oh wow, do you actually use this? :P I never finished my blogging library so never got it to the point where I was relying on it :)

from watchful.

subsetpark avatar subsetpark commented on June 23, 2024

I don't... yet :) But I am starting a new project that would benefit from it. Maybe the first step would be to extract the threaded parts from the basic bindings.

from watchful.

pyrmont avatar pyrmont commented on June 23, 2024

Is the C interface for threads being deprecated? I compiled and ran this against the HEAD of master and while I get compilation warnings from Janet for my use of the thread/* functions in my Janet code, the C stuff all works fine.

If a rewrite is required, it looks to me like I'd probably want to use janet_ev_post_event to send the 'event' of the changed file to the event loop.

from watchful.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.