Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
elixir__file_system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bioroboticslab
robofish
electrofish
vendor
elixir__file_system
Commits
d1b1657e
Commit
d1b1657e
authored
8 years ago
by
Xiangrong Hao
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #9 from thbar/custom-listener-args
Support optional listener args
parents
d457514a
1300de73
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+12
-0
12 additions, 0 deletions
README.md
lib/exfswatch.ex
+3
-2
3 additions, 2 deletions
lib/exfswatch.ex
lib/exfswatch/worker.ex
+8
-7
8 additions, 7 deletions
lib/exfswatch/worker.ex
with
23 additions
and
9 deletions
README.md
+
12
−
0
View file @
d1b1657e
...
@@ -60,6 +60,18 @@ Execute in iex
...
@@ -60,6 +60,18 @@ Execute in iex
iex
>
Monitor.start
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:
```
elixir
use
ExFSWatch
,
dirs:
[
"/tmp/fswatch"
],
listener_extra_args:
"--latency=0.0"
```
See the
[
fs source
](
https://github.com/synrc/fs/tree/master/c_src
)
for more details.
## List Events from Backend
## List Events from Backend
```
shell
```
shell
...
...
This diff is collapsed.
Click to expand it.
lib/exfswatch.ex
+
3
−
2
View file @
d1b1657e
require
Logger
require
Logger
defmodule
ExFSWatch
do
defmodule
ExFSWatch
do
defmacro
__using__
(
[
dirs:
dirs
]
)
do
defmacro
__using__
(
options
)
do
quote
do
quote
do
def
__dirs__
,
do
:
unquote
(
dirs
)
def
__dirs__
,
do
:
unquote
(
Keyword
.
fetch!
(
options
,
:dirs
))
def
__listener_extra_args__
,
do
:
unquote
(
Keyword
.
get
(
options
,
:listener_extra_args
,
''
))
def
start
,
do
:
ExFSWatch
.
Supervisor
.
start_child
__MODULE__
def
start
,
do
:
ExFSWatch
.
Supervisor
.
start_child
__MODULE__
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
lib/exfswatch/worker.ex
+
8
−
7
View file @
d1b1657e
...
@@ -9,7 +9,7 @@ defmodule ExFSWatch.Worker do
...
@@ -9,7 +9,7 @@ defmodule ExFSWatch.Worker do
def
init
(
module
)
do
def
init
(
module
)
do
backend
=
ExFSWatch
.
backend
backend
=
ExFSWatch
.
backend
port
=
start_port
(
backend
,
module
.
__dirs__
)
port
=
start_port
(
backend
,
module
.
__dirs__
,
module
.
__listener_extra_args__
)
{
:ok
,
%
__MODULE__
{
port:
port
,
backend:
backend
,
module:
module
}}
{
:ok
,
%
__MODULE__
{
port:
port
,
backend:
backend
,
module:
module
}}
end
end
...
@@ -29,15 +29,16 @@ defmodule ExFSWatch.Worker do
...
@@ -29,15 +29,16 @@ defmodule ExFSWatch.Worker do
end
end
defp
start_port
(
:fsevents
,
path
)
do
defp
start_port
(
:fsevents
,
path
,
listener_extra_args
)
do
path
=
path
|>
format_path
path
=
path
|>
format_path
args
=
[
listener_extra_args
,
'-F'
|
path
]
Port
.
open
({
:spawn_executable
,
:fsevents
.
find_executable
()},
Port
.
open
({
:spawn_executable
,
:fsevents
.
find_executable
()},
[
:stream
,
:exit_status
,
{
:line
,
16384
},
{
:args
,
[
'-F'
|
path
]
},
{
:cd
,
System
.
tmp_dir!
}]
[
:stream
,
:exit_status
,
{
:line
,
16384
},
{
:args
,
args
},
{
:cd
,
System
.
tmp_dir!
}]
)
)
end
end
defp
start_port
(
:inotifywait
,
path
)
do
defp
start_port
(
:inotifywait
,
path
,
listener_extra_args
)
do
path
=
path
|>
format_path
path
=
path
|>
format_path
args
=
[
'-c'
,
'inotifywait $0 $@ & PID=$!; read a; kill $PID'
,
args
=
[
listener_extra_args
,
'-c'
,
'inotifywait $0 $@ & PID=$!; read a; kill $PID'
,
'-m'
,
'-e'
,
'close_write'
,
'-e'
,
'moved_to'
,
'-e'
,
'create'
,
'-e'
,
'-m'
,
'-e'
,
'close_write'
,
'-e'
,
'moved_to'
,
'-e'
,
'create'
,
'-e'
,
'delete_self'
,
'-e'
,
'delete'
,
'-r'
|
path
'delete_self'
,
'-e'
,
'delete'
,
'-r'
|
path
]
]
...
@@ -45,9 +46,9 @@ defmodule ExFSWatch.Worker do
...
@@ -45,9 +46,9 @@ defmodule ExFSWatch.Worker do
[
:stream
,
:exit_status
,
{
:line
,
16384
},
{
:args
,
args
},
{
:cd
,
System
.
tmp_dir!
}]
[
:stream
,
:exit_status
,
{
:line
,
16384
},
{
:args
,
args
},
{
:cd
,
System
.
tmp_dir!
}]
)
)
end
end
defp
start_port
(
:"inotifywait_win32"
,
path
)
do
defp
start_port
(
:"inotifywait_win32"
,
path
,
listener_extra_args
)
do
path
=
path
|>
format_path
path
=
path
|>
format_path
args
=
[
'-m'
,
'-r'
|
path
]
args
=
[
listener_extra_args
,
'-m'
,
'-r'
|
path
]
Port
.
open
({
:spawn_executable
,
:"inotifywait_win32"
.
find_executable
()},
Port
.
open
({
:spawn_executable
,
:"inotifywait_win32"
.
find_executable
()},
[
:stream
,
:exit_status
,
{
:line
,
16384
},
{
:args
,
args
},
{
:cd
,
System
.
tmp_dir!
}]
[
:stream
,
:exit_status
,
{
:line
,
16384
},
{
:args
,
args
},
{
:cd
,
System
.
tmp_dir!
}]
)
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment