async_cable 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7a73611b6db5ff3e6f0377115d65a02dc9ce18f5
4
- data.tar.gz: a8982f7401992a3ef2ec0dd6bbb6f10309161682
2
+ SHA256:
3
+ metadata.gz: 51ecb6cb916b09cf5f40b62a9be1ddd360fabbb782977ec5da1f1a0babfbc361
4
+ data.tar.gz: 3036bbc16779cd6211e6b5f3d513028f84ccab08491395c844307fed7d4caf85
5
5
  SHA512:
6
- metadata.gz: 93f951f2178542ba41962a862e59f1ab0fefffdb2528ffbf785923e654363dd78ae550aff6872c3f525cdaf0706f1666b5a295d14a5445884c9512abd2247ade
7
- data.tar.gz: 598bd856f068b973db1339651e39089c08b28029734816bf3d13e7060cee3c868655832c682758e2cfb3ab2ff274a20177c00c5919818e70f99d06b291011960
6
+ metadata.gz: 480548a0bcf0e13f62fccb45cdaac42223f0573d552420b2c9ea286f2b1561ff0d6d8195cb20494b689e4c5aa387d7519d47355f67d0b2c54c32b6353f3e9a35
7
+ data.tar.gz: 742caf72b09cee54c0b36a1014bd794b9f59bbca68c88c9bf9df387c0bfad191b1a633a2c735ae9abf2b225d5e2ee518fd469823ede76acf86f81cad8b1d2882
@@ -1,4 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.2.0
4
+ * fix config.rb requiring
5
+ * broadcast async connection iteration
6
+
3
7
  ### 0.1.0
4
8
  * initial version
data/README.md CHANGED
@@ -92,6 +92,10 @@ example of JS code for connecting with websocket server
92
92
  };
93
93
  ```
94
94
 
95
+ ## Development
96
+
97
+ will use [Semver](https://semver.org) from version `1.0.0`
98
+
95
99
  ## Contributing
96
100
 
97
101
  Bug reports and pull requests are welcome on GitHub at https://github.com/senid231/async_cable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/async_cable/blob/master/CODE_OF_CONDUCT.md).
@@ -16,7 +16,7 @@ module AsyncCable
16
16
 
17
17
  def broadcast(data)
18
18
  config.logger.debug { "#{name}.broadcast data=#{data.inspect}" }
19
- Registry.find.each { |conn| conn.transmit(data) }
19
+ Registry.each { |conn| conn.transmit(data) }
20
20
  end
21
21
 
22
22
  module_function :configure, :config, :broadcast
@@ -1,3 +1,4 @@
1
+ require 'anyway_config'
1
2
  require 'null_logger'
2
3
 
3
4
  module AsyncCable
@@ -26,7 +26,7 @@ module AsyncCable
26
26
  def broadcast(stream_name, data)
27
27
  logger.debug { "#{name}.broadcast data=#{data.inspect}" }
28
28
 
29
- Registry.find(channel_name, stream_name).each do |conn|
29
+ Registry.each(channel_name, stream_name) do |conn|
30
30
  conn.transmit(data) unless conn.closed?
31
31
  end
32
32
  end
@@ -46,6 +46,15 @@ module AsyncCable
46
46
  end
47
47
  end
48
48
 
49
+ # Iterate connections asynchronously.
50
+ # @param channel_name [String,NilClass]
51
+ # @param stream_name [String,NilClass]
52
+ # @yield connection [AsyncCable::Connection]
53
+ def each(channel_name = nil, stream_name = nil, &block)
54
+ list = find(channel_name, stream_name)
55
+ Util.each_async(list, &block)
56
+ end
57
+
49
58
  private
50
59
 
51
60
  def subscribers
@@ -0,0 +1,27 @@
1
+ module AsyncCable
2
+ module Util
3
+ # @param parent [Async::Task,NilClass] parent task for new one.
4
+ # @param schedule [Boolean] run now if true, otherwise will be run at next reactor loop cycle.
5
+ # @return [Async::Task] return created task.
6
+ def create_task(parent = Async::Task.current?, schedule = false, &block)
7
+ task = Async::Task.new(parent, &block)
8
+ if schedule
9
+ Async::Task.current.reactor << task.fiber
10
+ else
11
+ task.run
12
+ end
13
+ task
14
+ end
15
+
16
+ # Each yield will be executed within it's own fiber.
17
+ # @param list [Array] list that will be iterable.
18
+ # @param args [Array] parent, schedule @see #create_task (optional).
19
+ def each_async(list, *args)
20
+ list.each do |item|
21
+ create_task(*args) { yield item }
22
+ end
23
+ end
24
+
25
+ module_function :create_task, :each_async
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module AsyncCable
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async_cable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-02 00:00:00.000000000 Z
11
+ date: 2020-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-websocket
@@ -90,6 +90,7 @@ files:
90
90
  - lib/async_cable/errors.rb
91
91
  - lib/async_cable/registry.rb
92
92
  - lib/async_cable/server.rb
93
+ - lib/async_cable/util.rb
93
94
  - lib/async_cable/version.rb
94
95
  homepage: https://github.com/senid231/async_cable
95
96
  licenses:
@@ -113,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  - !ruby/object:Gem::Version
114
115
  version: '0'
115
116
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.4.8
117
+ rubygems_version: 3.0.1
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Dead simple websocket middleware for Rack async app.