From 4a7b11d5d857a0f5ce6eb8af7a6dfcb94f31fcfa Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 13 Mar 2009 18:49:53 -0700 Subject: Less ceremony --- .../lib/action_view/body_parts/concurrent_block.rb | 25 +++++++++++++++++ actionpack/lib/action_view/body_parts/future.rb | 10 ------- actionpack/lib/action_view/body_parts/queued.rb | 18 ------------ actionpack/lib/action_view/body_parts/threaded.rb | 32 ---------------------- 4 files changed, 25 insertions(+), 60 deletions(-) create mode 100644 actionpack/lib/action_view/body_parts/concurrent_block.rb delete mode 100644 actionpack/lib/action_view/body_parts/future.rb delete mode 100644 actionpack/lib/action_view/body_parts/queued.rb delete mode 100644 actionpack/lib/action_view/body_parts/threaded.rb (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_view/body_parts/concurrent_block.rb b/actionpack/lib/action_view/body_parts/concurrent_block.rb new file mode 100644 index 0000000000..28a3a3bf4d --- /dev/null +++ b/actionpack/lib/action_view/body_parts/concurrent_block.rb @@ -0,0 +1,25 @@ +module ActionView + module BodyParts + class ConcurrentBlock + def initialize(&block) + @block = block + @body = [] + start + end + + def to_s + finish + @body.join + end + + protected + def start + @worker = Thread.new { @block.call(@body) } + end + + def finish + @worker.join if @worker && @worker.alive? + end + end + end +end diff --git a/actionpack/lib/action_view/body_parts/future.rb b/actionpack/lib/action_view/body_parts/future.rb deleted file mode 100644 index f03c2b395b..0000000000 --- a/actionpack/lib/action_view/body_parts/future.rb +++ /dev/null @@ -1,10 +0,0 @@ -module ActionView - module BodyParts - class Future - def to_s - finish - body - end - end - end -end diff --git a/actionpack/lib/action_view/body_parts/queued.rb b/actionpack/lib/action_view/body_parts/queued.rb deleted file mode 100644 index 618999742b..0000000000 --- a/actionpack/lib/action_view/body_parts/queued.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'action_view/body_parts/future' - -module ActionView - module BodyParts - class Queued < Future - attr_reader :body - - def initialize(job) - @receipt = enqueue(job) - end - - protected - def finish - @body = redeem(@receipt) - end - end - end -end diff --git a/actionpack/lib/action_view/body_parts/threaded.rb b/actionpack/lib/action_view/body_parts/threaded.rb deleted file mode 100644 index a2347a2f0e..0000000000 --- a/actionpack/lib/action_view/body_parts/threaded.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'action_view/body_parts/future' - -module ActionView - module BodyParts - class Threaded < Future - def initialize(concurrent = false, &block) - @block = block - @parts = [] - concurrent ? start : work - end - - protected - def work - @block.call(@parts) - end - - def body - str = '' - @parts.each { |part| str << part.to_s } - str - end - - def start - @worker = Thread.new { work } - end - - def finish - @worker.join if @worker && @worker.alive? - end - end - end -end -- cgit v1.2.3