johnae / spook

Lightweight programmable evented utility based on LuaJIT and ljsyscall
Other
35 stars 0 forks source link

Handle more events, like deleted, moved etc #17

Closed johnae closed 7 years ago

johnae commented 8 years ago

This requires some directory diffing and probably restructuring too. It may be very useful for certain tasks though.

johnae commented 8 years ago

Working on this and it's very promising. Libuv will be removed and direct system calls will replace it. Also see: https://github.com/johnae/spook/issues/9

johnae commented 8 years ago

Having worked on a Linux implementation using just syscalls (inotify/epoll/timerfd) and planning on a kqueue implementation for the BSD:s (including OS X), something comes to mind:

It seems as if spook could benefit alot from being less centered around running specs (which it was originally built to do). I am using it every day for that specific purpose so I don't want to mess that up since it does that really well. But still, I can envision so many other things it could do.

I believe (with a little ideas from friends) that it would be quite awesome if it was even more programmable and didn't entangle the whole thing with the idea of notifications for example, or the (soft) requirement that all functions return a boolean to indicate success. To me, this turns out to not be entirely trivial, but it ought to be perfectly doable.

Basically, I'd like to simplify this into:

watch "mydir", ->
    on_changed "^spec/(.*).moon", (event, name) ->
         os.execute "busted spec/#{name}.moon"

Just that. Any function could be run and it should be just a function. I also plan to expose timers in some way, sort of like:

timer 1.0, (t) ->
    print "Hello again 1 second later"
    t\again! -- for a recurring timer

Exposing timers would enable me to build some other things on top of spook that I've been toying with.

So, how to deal with notifications a la rspec? I'm not sure actually. One obvious way is of course that you load some library and do something like this:

notifier = require 'my_notifier'
watch "lib", ->
    on_changed "^lib/(.*).moon", (event, name) ->
         notifier\start mapped_file: "spec/#{name}.moon", changed_file: event.path
         _, _, status = os.execute "busted spec/#{name}.moon"
         success = status == 0
         notifier\finish mapped_file: "spec/#{name}.moon", changed_file: event.path, :success

Perhaps not such a horrible idea after all and it's clearly exposed. Spook would become more of an enabler than an integrated testing tool I guess, but I kind of like that.

johnae commented 7 years ago

Work ongoing in https://github.com/johnae/spook/pull/19

johnae commented 7 years ago

Completed in 0.7.0.