zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

file_system.ex (1529B)


      1 defmodule FileSystem do
      2   @moduledoc File.read!("README.md")
      3 
      4   @doc """
      5   ## Options
      6 
      7     * `:dirs` ([string], required), the dir list to monitor
      8 
      9     * `:backend` (atom, optional), default backends: `:fs_mac`
     10       for `macos`, `:fs_inotify` for `linux`, `freebsd` and `openbsd`,
     11       `:fs_windows` for `windows`
     12 
     13     * `:name` (atom, optional), `name` can be used to subscribe as
     14       the same as pid when the `name` is given. The `name` should
     15       be the name of worker process.
     16 
     17     * All rest options will treated as backend options. See backend
     18       module documents for more details.
     19 
     20   ## Example
     21 
     22   Simple usage:
     23 
     24       iex> {:ok, pid} = FileSystem.start_link(dirs: ["/tmp/fs"])
     25       iex> FileSystem.subscribe(pid)
     26 
     27   Get instant notifications on file changes for Mac OS X:
     28 
     29       iex> FileSystem.start_link(dirs: ["/path/to/some/files"], latency: 0)
     30 
     31   Named monitor with specified backend:
     32 
     33       iex> FileSystem.start_link(backend: :fs_mac, dirs: ["/tmp/fs"], name: :worker)
     34       iex> FileSystem.subscribe(:worker)
     35   """
     36   @spec start_link(Keyword.t) :: GenServer.on_start()
     37   def start_link(options) do
     38     FileSystem.Worker.start_link(options)
     39   end
     40 
     41   @doc """
     42   Register the current process as a subscriber of a file_system worker.
     43   The pid you subscribed from will now receive messages like
     44 
     45       {:file_event, worker_pid, {file_path, events}}
     46       {:file_event, worker_pid, :stop}
     47   """
     48   @spec subscribe(GenServer.server) :: :ok
     49   def subscribe(pid) do
     50     GenServer.call(pid, :subscribe)
     51   end
     52 end