Module: Mycel
- Defined in:
- lib/mycel.rb,
lib/mycel/version.rb
Defined Under Namespace
Modules: Callbacks, Channel, Codec, Framing, RPC, Transport Classes: ThreadPool
Constant Summary collapse
- VERSION =
The version of the mycel gem
"0.1.1"
Class Method Summary collapse
-
.current_session ⇒ Object
Cross-cutting: Current session context =========================================================================.
- .current_session_id ⇒ Object
- .with_current_session(session) ⇒ Object
Class Method Details
.current_session ⇒ Object
Cross-cutting: Current session context
During execution of a registered RPC method handler (and any code it calls — helpers, services, plugins), ‘Mycel.current_session` returns the `Mycel::Channel::Session` whose peer initiated the call. Outside such a context (e.g. plain library code, or after the handler returns) it is nil.
This is implemented with ‘Thread.current` rather than a block argument so that handlers retain their existing signatures and any code at any depth can ask “who called me?” without having to thread a session_id through every method. Concurrent calls land on independent threads (mycel spawns a worker per inbound Job by default), so the values do not bleed between peers.
Test fixtures and code that wants to invoke a handler outside the normal mycel dispatch path can use ‘Mycel.with_current_session(fake_session) { … }` to set the context manually.
43 44 45 |
# File 'lib/mycel.rb', line 43 def self.current_session Thread.current[:mycel_current_session] end |
.current_session_id ⇒ Object
47 48 49 |
# File 'lib/mycel.rb', line 47 def self.current_session_id current_session&.session_id end |
.with_current_session(session) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/mycel.rb', line 51 def self.with_current_session(session) prev = Thread.current[:mycel_current_session] Thread.current[:mycel_current_session] = session yield ensure Thread.current[:mycel_current_session] = prev end |