Skip to content
Snippets Groups Projects
Select Git revision
  • 1300de73f44b0a0d117c5fcb763fd883c2dda8ac
  • master default protected
  • dev
3 results

elixir__file_system

  • Clone with SSH
  • Clone with HTTPS
  • user avatar
    Thibaut Barrère authored
    1300de73
    History
    Name Last commit Last update
    config
    lib
    test
    .gitignore
    LICENSE
    README.md
    mix.exs

    ExFSWatch

    A file change watcher wrapper based on fs

    System Support

    Just like fs

    • Mac fsevent
    • Linux inotify
    • Windows inotify-win (untested)

    NOTE: On Linux you need to install inotify-tools.

    Usage

    Put exfswatch in the deps and application part of your mix.exs

    defmodule Excellent.Mixfile do
      use Mix.Project
    
      def project do
      ...
      end
    
      def application do
        [applications: [:exfswatch, :logger]]
      end
    
      defp deps do
        [
          { :exfswatch, "~> 0.1.0", only: :test },
        ]
      end
      ...
    end

    write lib/monitor.ex

    defmodule Monitor do
      use ExFSWatch, dirs: ["/tmp/fswatch"]
    
      def callback(:stop) do
        IO.puts "STOP"
      end
    
      def callback(file_path, events) do
        IO.inspect {file_path, events}
      end
    end

    Execute in iex

    iex > Monitor.start

    Tweaking behaviour via listener extra arguments

    For each platform, you can pass extra arguments to the underlying listener process via the listener_extra_args option.

    Here is an example to get instant notifications on file changes for Mac OS X:

    use ExFSWatch, dirs: ["/tmp/fswatch"], listener_extra_args: "--latency=0.0"

    See the fs source for more details.

    List Events from Backend

    iex > ExFSWatch.known_events

    TODO

    • GenEvent mode
    • Unit Testing