Comments (4)
@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 towatchful/watch
returns a fiber. If the consumer wants to stop the watch cleanly, they callwatchful/cancel
on the fiber. -
Hard:
watchful/monitor
will create a monitor object for a path with some (optional) options. The consumer can then usewatchful/start
andwatchful/stop
with the monitor object to start and stop the monitor manually. A call towatchful/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.
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.
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from watchful.