em-cometio-client 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.0.3 2013-3-5
2
+
3
+ * modify default timeout
4
+ * add timeout property
5
+
1
6
  === 0.0.2 2013-3-4
2
7
 
3
8
  * add test
data/README.md CHANGED
@@ -35,10 +35,8 @@ EM::run do
35
35
  end
36
36
 
37
37
  ## push "chat" event to Server
38
- EM::defer do
39
- loop do
40
- client.push :chat, {:message => Time.now.to_s, :name => 'clock'}
41
- end
38
+ EM::add_periodic_timer 10 do
39
+ client.push :chat, {:message => Time.now.to_s, :name => 'clock'}
42
40
  end
43
41
  end
44
42
  ```
@@ -3,17 +3,19 @@ module EventMachine
3
3
  class Client
4
4
  include EventEmitter
5
5
  attr_reader :url, :session
6
+ attr_accessor :timeout
6
7
 
7
8
  def initialize(url)
8
9
  raise ArgumentError, "invalid URL (#{url})" unless url.kind_of? String and url =~ /^https?:\/\/.+/
9
10
  @url = url
10
11
  @session = nil
11
12
  @running = false
13
+ @timeout = 120
12
14
  end
13
15
 
14
16
  def push(type, data)
15
17
  that = self
16
- http = EM::HttpRequest.new(@url, :connect_timeout => 60000).
18
+ http = EM::HttpRequest.new(@url, :connect_timeout => 10).
17
19
  post(:body => {:type => type, :data => data, :session => @session})
18
20
  http.callback do |res|
19
21
  end
@@ -40,12 +42,13 @@ module EventMachine
40
42
 
41
43
  private
42
44
  def get
43
- http = EM::HttpRequest.new("#{@url}?session=#{@session}", :connect_timeout => 60000).get
45
+ http = EM::HttpRequest.new("#{@url}?session=#{@session}", :connect_timeout => @timeout).get
44
46
  http.callback do |res|
45
47
  begin
46
48
  data = JSON.parse res.response
47
49
  self.emit data['type'], data['data']
48
- rescue
50
+ rescue JSON::ParserError
51
+ rescue StandardError
49
52
  self.emit :error, "CometIO get error"
50
53
  sleep 10
51
54
  end
@@ -1,7 +1,7 @@
1
1
  module EventMachine
2
2
  module CometIO
3
3
  class Client
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-cometio-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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: 2013-03-04 00:00:00.000000000 Z
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine