File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ require 'delegate'
2+ require 'concurrent/executor/executor'
13require 'concurrent/logging'
24
35module Concurrent
@@ -85,6 +87,27 @@ def work(job)
8587
8688 call_job job if job
8789 end
90+ end
91+
92+ # A wrapper/delegator for any `Executor` or `ExecutorService` that
93+ # guarantees serialized execution of tasks.
94+ #
95+ # @see [SimpleDelegator](http://www.ruby-doc.org/stdlib-2.1.2/libdoc/delegate/rdoc/SimpleDelegator.html)
96+ # @see Concurrent::SerializedExecution
97+ class SerializedExecutionDelegator < SimpleDelegator
98+ include SerialExecutor
8899
100+ def initialize ( executor )
101+ @executor = executor
102+ @serializer = SerializedExecution . new
103+ super ( executor )
104+ end
105+
106+ # @!macro executor_method_post
107+ def post ( *args , &task )
108+ raise ArgumentError . new ( 'no block given' ) unless block_given?
109+ return false unless running?
110+ @serializer . post ( @executor , *args , &task )
111+ end
89112 end
90113end
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+ require_relative 'thread_pool_shared'
3+
4+ module Concurrent
5+
6+ describe SerializedExecutionDelegator do
7+
8+ subject { SerializedExecutionDelegator . new ( ImmediateExecutor . new ) }
9+
10+ it_should_behave_like :executor_service
11+ end
12+ end
You can’t perform that action at this time.
0 commit comments