Class: Wee::Session::ThreadSerializer
Overview
This serializer ensures that all requests of a session are executed within the same thread. This is required if continuations are going to be used.
You can run multiple sessions within the same ThreadSerializer, or allocate one ThreadSerializer (and as such one Thread) per session as you want.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ ThreadSerializer
constructor
A new instance of ThreadSerializer.
Constructor Details
#initialize ⇒ ThreadSerializer
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wee/session.rb', line 33 def initialize @in, @out = Queue.new, Queue.new @thread = Thread.new { Thread.abort_on_exception = true while true env = @in.pop @out.push(env['wee.session'].call(env)) end } end |
Instance Method Details
#call(env) ⇒ Object
44 45 46 47 |
# File 'lib/wee/session.rb', line 44 def call(env) @in.push(env) @out.pop end |