Class: Wee::Session::ThreadSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/wee/session.rb

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

Constructor Details

#initializeThreadSerializer

Returns a new instance of ThreadSerializer.



31
32
33
34
35
36
37
38
39
40
# File 'lib/wee/session.rb', line 31

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



42
43
44
45
# File 'lib/wee/session.rb', line 42

def call(env)
  @in.push(env)
  @out.pop
end