async_cable 0.1.0 → 0.2.0
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +4 -0
- data/README.md +4 -0
- data/lib/async_cable.rb +1 -1
- data/lib/async_cable/config.rb +1 -0
- data/lib/async_cable/connection.rb +1 -1
- data/lib/async_cable/registry.rb +9 -0
- data/lib/async_cable/util.rb +27 -0
- data/lib/async_cable/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51ecb6cb916b09cf5f40b62a9be1ddd360fabbb782977ec5da1f1a0babfbc361
|
4
|
+
data.tar.gz: 3036bbc16779cd6211e6b5f3d513028f84ccab08491395c844307fed7d4caf85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 480548a0bcf0e13f62fccb45cdaac42223f0573d552420b2c9ea286f2b1561ff0d6d8195cb20494b689e4c5aa387d7519d47355f67d0b2c54c32b6353f3e9a35
|
7
|
+
data.tar.gz: 742caf72b09cee54c0b36a1014bd794b9f59bbca68c88c9bf9df387c0bfad191b1a633a2c735ae9abf2b225d5e2ee518fd469823ede76acf86f81cad8b1d2882
|
data/CHANGELOG.md
CHANGED
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).
|
data/lib/async_cable.rb
CHANGED
@@ -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.
|
19
|
+
Registry.each { |conn| conn.transmit(data) }
|
20
20
|
end
|
21
21
|
|
22
22
|
module_function :configure, :config, :broadcast
|
data/lib/async_cable/config.rb
CHANGED
@@ -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.
|
29
|
+
Registry.each(channel_name, stream_name) do |conn|
|
30
30
|
conn.transmit(data) unless conn.closed?
|
31
31
|
end
|
32
32
|
end
|
data/lib/async_cable/registry.rb
CHANGED
@@ -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
|
data/lib/async_cable/version.rb
CHANGED
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.
|
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-
|
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
|
-
|
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.
|