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'
1
3
require 'concurrent/logging'
2
4
3
5
module Concurrent
@@ -85,6 +87,27 @@ def work(job)
85
87
86
88
call_job job if job
87
89
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
88
99
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
89
112
end
90
113
end
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