guard-livereload 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require 'em-websocket'
2
2
  require 'multi_json'
3
+ require 'thread'
3
4
 
4
5
  module Guard
5
6
  class LiveReload
@@ -8,6 +9,7 @@ module Guard
8
9
  attr_reader :thread, :web_sockets
9
10
 
10
11
  def initialize(options)
12
+ @mutex = Mutex.new
11
13
  @web_sockets = []
12
14
  @options = options
13
15
  @thread = start_threaded_reactor(options)
@@ -18,15 +20,17 @@ module Guard
18
20
  end
19
21
 
20
22
  def reload_browser(paths = [])
21
- UI.info "Reloading browser: #{paths.join(' ')}"
22
- paths.each do |path|
23
- data = MultiJson.encode(['refresh', {
24
- :path => "#{Dir.pwd}/#{path}",
25
- :apply_js_live => @options[:apply_js_live],
26
- :apply_css_live => @options[:apply_css_live]
27
- }])
28
- UI.debug data
29
- @web_sockets.each { |ws| ws.send(data) }
23
+ @mutex.synchronize do
24
+ UI.info "Reloading browser: #{paths.join(' ')}"
25
+ paths.each do |path|
26
+ data = MultiJson.encode(['refresh', {
27
+ :path => "#{Dir.pwd}/#{path}",
28
+ :apply_js_live => @options[:apply_js_live],
29
+ :apply_css_live => @options[:apply_css_live]
30
+ }])
31
+ UI.debug data
32
+ @web_sockets.each { |ws| ws.send(data) }
33
+ end
30
34
  end
31
35
  end
32
36
 
@@ -38,13 +42,15 @@ module Guard
38
42
  UI.info "LiveReload #{options[:api_version]} is waiting for a browser to connect."
39
43
  EventMachine.start_server(options[:host], options[:port], EventMachine::WebSocket::Connection, {}) do |ws|
40
44
  ws.onopen do
41
- begin
42
- UI.info "Browser connected."
43
- ws.send "!!ver:#{options[:api_version]}"
44
- @web_sockets << ws
45
- rescue
46
- UI.errror $!
47
- UI.errror $!.backtrace
45
+ @mutex.synchronize do
46
+ begin
47
+ UI.info "Browser connected."
48
+ ws.send "!!ver:#{options[:api_version]}"
49
+ @web_sockets << ws
50
+ rescue
51
+ UI.errror $!
52
+ UI.errror $!.backtrace
53
+ end
48
54
  end
49
55
  end
50
56
 
@@ -53,8 +59,10 @@ module Guard
53
59
  end
54
60
 
55
61
  ws.onclose do
56
- @web_sockets.delete ws
57
- UI.info "Browser disconnected."
62
+ @mutex.synchronize do
63
+ @web_sockets.delete ws
64
+ UI.info "Browser disconnected."
65
+ end
58
66
  end
59
67
  end
60
68
  end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module LiveReloadVersion
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-livereload
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-16 00:00:00.000000000 Z
12
+ date: 2012-10-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard