Skip to content

Commit 2ce6c95

Browse files
committed
Created SerializedExecutionDelegator to wrap SerializedExecution.
1 parent 56b5e2b commit 2ce6c95

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/concurrent/executor/serialized_execution.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'delegate'
2+
require 'concurrent/executor/executor'
13
require 'concurrent/logging'
24

35
module 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
90113
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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

0 commit comments

Comments
 (0)