anycable-core 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/anycable/broadcast_adapters/base.rb +51 -2
- data/lib/anycable/version.rb +1 -1
- data/lib/anycable.rb +2 -2
- data/sig/anycable/broadcast_adapters/base.rbs +11 -1
- data/sig/anycable.rbs +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a7b2ae33dc506f328c7ce62c3c4c80eabb17ed36ca4826808caeb0534a8b2ab
|
4
|
+
data.tar.gz: 2cfae2f0b55718269c33dfc5877d55a2d210d9fa99f0aca85c2899720c0cf350
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b10e485726fd3f48791883af759cfdbeb963a59798a3df7a5100e993891fdb8faff370d028f6b81010be79b2737405196e7f4988041c92896326b222eab4296a
|
7
|
+
data.tar.gz: a901c3958ed1d866a6d7d7f20fb7e8ede84bfabbba29136a022e8eaf3241d10aa437d02c163fa54d0fe7aad8fef701df2299968a20fc887b9348276bee11098a
|
data/CHANGELOG.md
CHANGED
@@ -7,8 +7,31 @@ module AnyCable
|
|
7
7
|
raise NotImplementedError
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def batching(enabled = true)
|
11
|
+
self.batching_enabled = enabled
|
12
|
+
yield
|
13
|
+
ensure
|
14
|
+
maybe_flush_batch
|
15
|
+
end
|
16
|
+
|
17
|
+
def start_batching
|
18
|
+
self.batching_enabled = true
|
19
|
+
end
|
20
|
+
|
21
|
+
def finish_batching
|
22
|
+
maybe_flush_batch
|
23
|
+
end
|
24
|
+
|
25
|
+
def batching?
|
26
|
+
Thread.current[:anycable_batching]&.last
|
27
|
+
end
|
28
|
+
|
29
|
+
def broadcast(stream, payload, options = nil)
|
30
|
+
if batching?
|
31
|
+
current_batch << {stream: stream, data: payload, meta: options}.compact
|
32
|
+
else
|
33
|
+
raw_broadcast({stream: stream, data: payload, meta: options}.compact.to_json)
|
34
|
+
end
|
12
35
|
end
|
13
36
|
|
14
37
|
def broadcast_command(command, **payload)
|
@@ -21,6 +44,32 @@ module AnyCable
|
|
21
44
|
|
22
45
|
private
|
23
46
|
|
47
|
+
def batching_enabled=(val)
|
48
|
+
# The stack must start with the true value,
|
49
|
+
# so we can check for emptiness to decide whether to flush
|
50
|
+
stack = batching_enabled_stack
|
51
|
+
stack << val if val || !stack.empty?
|
52
|
+
end
|
53
|
+
|
54
|
+
def batching_enabled_stack
|
55
|
+
Thread.current[:anycable_batching] ||= []
|
56
|
+
end
|
57
|
+
|
58
|
+
def current_batch
|
59
|
+
Thread.current[:anycable_batch] ||= []
|
60
|
+
end
|
61
|
+
|
62
|
+
def maybe_flush_batch
|
63
|
+
batching_enabled_stack.pop
|
64
|
+
return unless batching_enabled_stack.empty?
|
65
|
+
|
66
|
+
batch = current_batch
|
67
|
+
unless batch.empty?
|
68
|
+
raw_broadcast(batch.to_json)
|
69
|
+
end
|
70
|
+
current_batch.clear
|
71
|
+
end
|
72
|
+
|
24
73
|
def logger
|
25
74
|
AnyCable.logger
|
26
75
|
end
|
data/lib/anycable/version.rb
CHANGED
data/lib/anycable.rb
CHANGED
@@ -92,8 +92,8 @@ module AnyCable
|
|
92
92
|
|
93
93
|
# Raw broadcast message to the channel, sends only string!
|
94
94
|
# To send hash or object use ActionCable.server.broadcast instead!
|
95
|
-
def broadcast(
|
96
|
-
broadcast_adapter.broadcast(
|
95
|
+
def broadcast(...)
|
96
|
+
broadcast_adapter.broadcast(...)
|
97
97
|
end
|
98
98
|
|
99
99
|
def rpc_handler
|
@@ -1,7 +1,13 @@
|
|
1
1
|
module AnyCable
|
2
|
+
type broadcastOptions = {exclude_socket: String}
|
3
|
+
|
2
4
|
interface _BroadcastAdapter
|
3
5
|
def raw_broadcast: (String _data) -> void
|
4
|
-
def
|
6
|
+
def batching: (?bool enabled) { () -> untyped } -> untyped
|
7
|
+
def start_batching: () -> void
|
8
|
+
def finish_batching: () -> void
|
9
|
+
def batching?: () -> (bool | NilClass)
|
10
|
+
def broadcast: (String stream, String payload, ?broadcastOptions options) -> void
|
5
11
|
def broadcast_command: (String command, **untyped payload) -> void
|
6
12
|
def announce!: () -> void
|
7
13
|
end
|
@@ -13,6 +19,10 @@ module AnyCable
|
|
13
19
|
private
|
14
20
|
|
15
21
|
def logger: () -> Logger
|
22
|
+
def current_batch: () -> Array[untyped]
|
23
|
+
def maybe_flush_batch: () -> void
|
24
|
+
def batching_enabled_stack: () -> Array[bool]
|
25
|
+
def batching_enabled=: (bool) -> void
|
16
26
|
end
|
17
27
|
end
|
18
28
|
end
|
data/sig/anycable.rbs
CHANGED
@@ -36,6 +36,6 @@ module AnyCable
|
|
36
36
|
def self.server_callbacks: () -> Array[^() -> void]
|
37
37
|
def self.broadcast_adapter: () -> _BroadcastAdapter
|
38
38
|
def self.broadcast_adapter=: (untyped adapter) -> void
|
39
|
-
def self.broadcast: (String channel, String payload) -> void
|
39
|
+
def self.broadcast: (String channel, String payload, ?broadcastOptions options) -> void
|
40
40
|
def self.rpc_handler: () -> RPC::Handler
|
41
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anycable-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- palkan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anyway_config
|