Skip to content

Commit a0bc205

Browse files
committed
Created SerialExecutor 'type' module for interrogating objects.
1 parent 2ce6c95 commit a0bc205

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

lib/concurrent/executor/executor.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,58 @@
55
module Concurrent
66

77
module Executor
8+
9+
# @!macro [attach] executor_module_method_can_overflow_question
10+
#
11+
# Does the task queue have a maximum size?
12+
#
13+
# @return [Boolean] True if the task queue has a maximum size else false.
14+
#
15+
# @note Always returns `false`
816
def can_overflow?
917
false
1018
end
19+
20+
# @!macro [attach] executor_module_method_serialized_question
21+
#
22+
# Does this executor guarantee serialization of its operations?
23+
#
24+
# @return [Boolean] True if the executor guarantees that all operations
25+
# will be post in the order they are received and no two operations may
26+
# occur simultaneously. Else false.
27+
#
28+
# @note Always returns `false`
29+
def serialized?
30+
false
31+
end
32+
end
33+
34+
# Indicates that the including `Executor` or `ExecutorService` guarantees
35+
# that all operations will occur in the order they are post and that no
36+
# two operations may occur simultaneously. This module provides no
37+
# functionality and provides no guarantees. That is the responsibility
38+
# of the including class. This module exists solely to allow the including
39+
# object to be interrogated for its serialization status.
40+
#
41+
# @example
42+
# class Foo
43+
# include Concurrent::SerialExecutor
44+
# end
45+
#
46+
# foo = Foo.new
47+
#
48+
# foo.is_a? Concurrent::Executor #=> true
49+
# foo.is_a? Concurrent::SerialExecutor #=> true
50+
# foo.serialized? #=> true
51+
module SerialExecutor
52+
include Executor
53+
54+
# @!macro executor_module_method_serialized_question
55+
#
56+
# @note Always returns `true`
57+
def serialized?
58+
true
59+
end
1160
end
1261

1362
module RubyExecutor

lib/concurrent/executor/immediate_executor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module Concurrent
55
class ImmediateExecutor
6-
include Executor
6+
include SerialExecutor
77

88
def initialize
99
@stopped = Concurrent::Event.new

lib/concurrent/executor/java_single_thread_executor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Concurrent
66
# @!macro single_thread_executor
77
class JavaSingleThreadExecutor
88
include JavaExecutor
9+
include SerialExecutor
910

1011
# Create a new thread pool.
1112
#

lib/concurrent/executor/java_thread_pool_executor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def initialize(opts = {})
9090
set_shutdown_hook
9191
end
9292

93+
# @!macro executor_module_method_can_overflow_question
9394
def can_overflow?
9495
@max_queue != 0
9596
end

lib/concurrent/executor/ruby_single_thread_executor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Concurrent
55
# @!macro single_thread_executor
66
class RubySingleThreadExecutor
77
include RubyExecutor
8+
include SerialExecutor
89

910
# Create a new thread pool.
1011
#

lib/concurrent/executor/ruby_thread_pool_executor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def initialize(opts = {})
100100
@last_gc_time = Time.now.to_f - [1.0, (@gc_interval * 2.0)].max
101101
end
102102

103+
# @!macro executor_module_method_can_overflow_question
103104
def can_overflow?
104105
@max_queue != 0
105106
end

0 commit comments

Comments
 (0)