Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Froze middleware talk

Froze middleware talk

I had given this talk at Deccan Ruby Conf 2017, Pune

Atul Bhosale

July 29, 2017
Tweet

More Decks by Atul Bhosale

Other Decks in Technology

Transcript

  1. # Non Thread safe code class Counter def initialize @counter

    = 0 end def call(_env) counter = @counter sleep 1 counter += 1 @counter = counter [200, { 'Content-Type' => 'text/html' }, ["#{@counter}"]] end end
  2. # Thread safe code class Counter def initialize @atomic =

    Concurrent::AtomicReference.new(0) end def call(_env) @atomic.update { |v| v + 1 } [200, { 'Content-Type' => 'text/html' }, ["{@atomic}"]] end end
  3. use (Class.new do def call(env) @a = 1 if env['PATH_INFO']

    == '/a' @app.call(env) end freeze_app end)