celluloid 0.16.0 → 0.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +394 -0
- data/LICENSE.txt +1 -1
- data/README.md +28 -15
- data/culture/CONDUCT.md +28 -0
- data/culture/Gemfile +9 -0
- data/culture/LICENSE.txt +22 -0
- data/culture/README.md +22 -0
- data/culture/Rakefile +5 -0
- data/culture/SYNC.md +70 -0
- data/culture/celluloid-culture.gemspec +18 -0
- data/culture/gems/README.md +39 -0
- data/culture/gems/dependencies.yml +85 -0
- data/culture/gems/loader.rb +101 -0
- data/culture/rubocop/README.md +38 -0
- data/culture/rubocop/lint.yml +8 -0
- data/culture/rubocop/metrics.yml +15 -0
- data/culture/rubocop/perf.yml +0 -0
- data/culture/rubocop/rubocop.yml +5 -0
- data/culture/rubocop/style.yml +57 -0
- data/culture/spec/gems_spec.rb +2 -0
- data/culture/spec/spec_helper.rb +0 -0
- data/culture/spec/sync_spec.rb +2 -0
- data/culture/sync.rb +56 -0
- data/culture/tasks/rspec.rake +5 -0
- data/culture/tasks/rubocop.rake +2 -0
- data/examples/basic_usage.rb +49 -0
- data/examples/futures.rb +38 -0
- data/examples/ring.rb +61 -0
- data/examples/simple_pmap.rb +14 -0
- data/examples/stack.rb +47 -0
- data/examples/timers.rb +72 -0
- data/lib/celluloid/actor/manager.rb +7 -0
- data/lib/celluloid/actor/system.rb +163 -0
- data/lib/celluloid/actor.rb +53 -71
- data/lib/celluloid/autostart.rb +1 -1
- data/lib/celluloid/backported.rb +2 -0
- data/lib/celluloid/call/async.rb +16 -0
- data/lib/celluloid/call/block.rb +22 -0
- data/lib/celluloid/call/sync.rb +70 -0
- data/lib/celluloid/calls.rb +24 -114
- data/lib/celluloid/cell.rb +32 -20
- data/lib/celluloid/condition.rb +5 -6
- data/lib/celluloid/core_ext.rb +1 -1
- data/lib/celluloid/current.rb +2 -0
- data/lib/celluloid/debug.rb +1 -0
- data/lib/celluloid/deprecate.rb +21 -0
- data/lib/celluloid/exceptions.rb +22 -16
- data/lib/celluloid/fiber.rb +3 -3
- data/lib/celluloid/future.rb +46 -8
- data/lib/celluloid/group/pool.rb +125 -0
- data/lib/celluloid/group/spawner.rb +68 -0
- data/lib/celluloid/group.rb +61 -0
- data/lib/celluloid/logging.rb +5 -5
- data/lib/celluloid/mailbox/evented.rb +74 -0
- data/lib/celluloid/mailbox.rb +15 -14
- data/lib/celluloid/managed.rb +3 -0
- data/lib/celluloid/notices.rb +15 -0
- data/lib/celluloid/proxies.rb +11 -0
- data/lib/celluloid/proxy/abstract.rb +50 -0
- data/lib/celluloid/proxy/actor.rb +37 -0
- data/lib/celluloid/proxy/async.rb +15 -0
- data/lib/celluloid/proxy/block.rb +28 -0
- data/lib/celluloid/proxy/cell.rb +66 -0
- data/lib/celluloid/proxy/future.rb +20 -0
- data/lib/celluloid/proxy/sync.rb +24 -0
- data/lib/celluloid/rspec.rb +67 -9
- data/lib/celluloid/system_events.rb +69 -14
- data/lib/celluloid/task/fibered.rb +45 -0
- data/lib/celluloid/task/threaded.rb +59 -0
- data/lib/celluloid/{tasks.rb → task.rb} +30 -38
- data/lib/celluloid/test.rb +1 -1
- data/lib/celluloid/thread.rb +6 -1
- data/lib/celluloid/version.rb +3 -0
- data/lib/celluloid.rb +151 -130
- data/spec/celluloid/actor/system_spec.rb +83 -0
- data/spec/celluloid/actor_spec.rb +2 -2
- data/spec/celluloid/block_spec.rb +67 -8
- data/spec/celluloid/calls_spec.rb +28 -23
- data/spec/celluloid/condition_spec.rb +23 -14
- data/spec/celluloid/evented_mailbox_spec.rb +1 -31
- data/spec/celluloid/future_spec.rb +15 -12
- data/spec/celluloid/group/elastic_spec.rb +0 -0
- data/spec/celluloid/group/pool_spec.rb +8 -0
- data/spec/celluloid/group/spawner_spec.rb +17 -0
- data/spec/celluloid/mailbox/evented_spec.rb +40 -0
- data/spec/celluloid/mailbox_spec.rb +1 -3
- data/spec/celluloid/misc/leak_spec.rb +73 -0
- data/spec/celluloid/proxy_spec.rb +33 -0
- data/spec/celluloid/task/fibered_spec.rb +5 -0
- data/spec/celluloid/task/threaded_spec.rb +5 -0
- data/spec/celluloid/timer_spec.rb +14 -16
- data/spec/deprecate/actor_system_spec.rb +72 -0
- data/spec/deprecate/block_spec.rb +52 -0
- data/spec/deprecate/calls_spec.rb +39 -0
- data/spec/deprecate/evented_mailbox_spec.rb +34 -0
- data/spec/deprecate/future_spec.rb +32 -0
- data/spec/deprecate/internal_pool_spec.rb +4 -0
- data/spec/shared/actor_examples.rb +1259 -0
- data/spec/shared/group_examples.rb +121 -0
- data/spec/shared/mailbox_examples.rb +87 -0
- data/{lib/celluloid/rspec → spec/shared}/task_examples.rb +9 -8
- data/spec/spec_helper.rb +5 -42
- data/spec/support/configure_rspec.rb +77 -0
- data/spec/support/coverage.rb +4 -0
- data/spec/support/crash_checking.rb +68 -0
- data/spec/support/debugging.rb +31 -0
- data/spec/support/env.rb +21 -0
- data/{lib/celluloid/rspec/example_actor_class.rb → spec/support/examples/actor_class.rb} +21 -2
- data/spec/support/examples/call_class.rb +37 -0
- data/spec/support/examples/evented_mailbox_class.rb +27 -0
- data/spec/support/includer.rb +6 -0
- data/spec/support/logging.rb +55 -0
- data/spec/support/loose_threads.rb +68 -0
- data/spec/support/reset_class_variables.rb +27 -0
- data/spec/support/sleep_and_wait.rb +14 -0
- data/spec/support/stubbing.rb +14 -0
- metadata +276 -78
- data/lib/celluloid/actor_system.rb +0 -107
- data/lib/celluloid/call_chain.rb +0 -13
- data/lib/celluloid/cpu_counter.rb +0 -34
- data/lib/celluloid/evented_mailbox.rb +0 -73
- data/lib/celluloid/fsm.rb +0 -186
- data/lib/celluloid/handlers.rb +0 -41
- data/lib/celluloid/internal_pool.rb +0 -159
- data/lib/celluloid/legacy.rb +0 -9
- data/lib/celluloid/links.rb +0 -36
- data/lib/celluloid/logger.rb +0 -93
- data/lib/celluloid/logging/incident.rb +0 -21
- data/lib/celluloid/logging/incident_logger.rb +0 -129
- data/lib/celluloid/logging/incident_reporter.rb +0 -48
- data/lib/celluloid/logging/log_event.rb +0 -20
- data/lib/celluloid/logging/ring_buffer.rb +0 -65
- data/lib/celluloid/method.rb +0 -32
- data/lib/celluloid/notifications.rb +0 -83
- data/lib/celluloid/pool_manager.rb +0 -146
- data/lib/celluloid/probe.rb +0 -73
- data/lib/celluloid/properties.rb +0 -24
- data/lib/celluloid/proxies/abstract_proxy.rb +0 -20
- data/lib/celluloid/proxies/actor_proxy.rb +0 -38
- data/lib/celluloid/proxies/async_proxy.rb +0 -31
- data/lib/celluloid/proxies/block_proxy.rb +0 -29
- data/lib/celluloid/proxies/cell_proxy.rb +0 -68
- data/lib/celluloid/proxies/future_proxy.rb +0 -35
- data/lib/celluloid/proxies/sync_proxy.rb +0 -36
- data/lib/celluloid/receivers.rb +0 -63
- data/lib/celluloid/registry.rb +0 -57
- data/lib/celluloid/responses.rb +0 -44
- data/lib/celluloid/rspec/actor_examples.rb +0 -1054
- data/lib/celluloid/rspec/mailbox_examples.rb +0 -84
- data/lib/celluloid/signals.rb +0 -23
- data/lib/celluloid/stack_dump.rb +0 -133
- data/lib/celluloid/supervision_group.rb +0 -169
- data/lib/celluloid/supervisor.rb +0 -22
- data/lib/celluloid/task_set.rb +0 -49
- data/lib/celluloid/tasks/task_fiber.rb +0 -43
- data/lib/celluloid/tasks/task_thread.rb +0 -53
- data/lib/celluloid/thread_handle.rb +0 -50
- data/lib/celluloid/uuid.rb +0 -38
- data/spec/celluloid/actor_system_spec.rb +0 -69
- data/spec/celluloid/cpu_counter_spec.rb +0 -82
- data/spec/celluloid/fsm_spec.rb +0 -107
- data/spec/celluloid/internal_pool_spec.rb +0 -52
- data/spec/celluloid/links_spec.rb +0 -45
- data/spec/celluloid/logging/ring_buffer_spec.rb +0 -38
- data/spec/celluloid/notifications_spec.rb +0 -120
- data/spec/celluloid/pool_spec.rb +0 -92
- data/spec/celluloid/probe_spec.rb +0 -121
- data/spec/celluloid/properties_spec.rb +0 -42
- data/spec/celluloid/registry_spec.rb +0 -64
- data/spec/celluloid/stack_dump_spec.rb +0 -64
- data/spec/celluloid/supervision_group_spec.rb +0 -65
- data/spec/celluloid/supervisor_spec.rb +0 -103
- data/spec/celluloid/tasks/task_fiber_spec.rb +0 -5
- data/spec/celluloid/tasks/task_thread_spec.rb +0 -5
- data/spec/celluloid/thread_handle_spec.rb +0 -26
- data/spec/celluloid/uuid_spec.rb +0 -11
|
@@ -1,14 +1,54 @@
|
|
|
1
1
|
module Celluloid
|
|
2
|
+
class Actor
|
|
3
|
+
# Handle high-priority system event messages
|
|
4
|
+
def handle_system_event(event)
|
|
5
|
+
if handler = SystemEvent.handle(event.class)
|
|
6
|
+
send(handler, event)
|
|
7
|
+
else
|
|
8
|
+
Internals::Logger.debug "Discarded message (unhandled): #{message}" if $CELLULOID_DEBUG
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
2
12
|
# High-priority internal system events
|
|
3
|
-
class SystemEvent
|
|
13
|
+
class SystemEvent
|
|
14
|
+
class << self
|
|
15
|
+
@@system_events = {}
|
|
16
|
+
def handle(type)
|
|
17
|
+
@@system_events[type]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def handler(&block)
|
|
21
|
+
fail ArgumentError, "SystemEvent handlers must be defined with a block." unless block
|
|
22
|
+
method = begin
|
|
23
|
+
handler = name
|
|
24
|
+
.split("::").last
|
|
25
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, "\1_\2")
|
|
26
|
+
.gsub(/([a-z\d])([A-Z])/, "\1_\2")
|
|
27
|
+
.tr("-", "_")
|
|
28
|
+
.downcase
|
|
29
|
+
:"handle_#{handler}"
|
|
30
|
+
end
|
|
31
|
+
Actor.send(:define_method, method, &block)
|
|
32
|
+
@@system_events[self] = method
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class LinkingEvent < SystemEvent
|
|
37
|
+
# Shared initializer for LinkingRequest and LinkingResponse
|
|
38
|
+
def initialize(actor, type)
|
|
39
|
+
@actor = actor
|
|
40
|
+
@type = type.to_sym
|
|
41
|
+
fail ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
4
45
|
|
|
5
46
|
# Request to link with another actor
|
|
6
|
-
class LinkingRequest < SystemEvent
|
|
47
|
+
class LinkingRequest < SystemEvent::LinkingEvent
|
|
7
48
|
attr_reader :actor, :type
|
|
8
49
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
raise ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type)
|
|
50
|
+
handler do |event|
|
|
51
|
+
event.process(links)
|
|
12
52
|
end
|
|
13
53
|
|
|
14
54
|
def process(links)
|
|
@@ -22,21 +62,22 @@ module Celluloid
|
|
|
22
62
|
end
|
|
23
63
|
|
|
24
64
|
# Response to a link request
|
|
25
|
-
class LinkingResponse
|
|
65
|
+
class LinkingResponse < SystemEvent::LinkingEvent
|
|
26
66
|
attr_reader :actor, :type
|
|
27
|
-
|
|
28
|
-
def initialize(actor, type)
|
|
29
|
-
@actor, @type = actor, type.to_sym
|
|
30
|
-
raise ArgumentError, "type must be link or unlink" unless [:link, :unlink].include?(@type)
|
|
31
|
-
end
|
|
32
67
|
end
|
|
33
68
|
|
|
34
69
|
# An actor has exited for the given reason
|
|
35
70
|
class ExitEvent < SystemEvent
|
|
36
71
|
attr_reader :actor, :reason
|
|
37
72
|
|
|
73
|
+
handler do |event|
|
|
74
|
+
@links.delete event.actor
|
|
75
|
+
@exit_handler.call(event)
|
|
76
|
+
end
|
|
77
|
+
|
|
38
78
|
def initialize(actor, reason = nil)
|
|
39
|
-
@actor
|
|
79
|
+
@actor = actor
|
|
80
|
+
@reason = reason
|
|
40
81
|
end
|
|
41
82
|
end
|
|
42
83
|
|
|
@@ -44,21 +85,35 @@ module Celluloid
|
|
|
44
85
|
class NamingRequest < SystemEvent
|
|
45
86
|
attr_reader :name
|
|
46
87
|
|
|
88
|
+
handler do |event|
|
|
89
|
+
@name = event.name
|
|
90
|
+
Celluloid::Probe.actor_named(self) if $CELLULOID_MONITORING
|
|
91
|
+
end
|
|
92
|
+
|
|
47
93
|
def initialize(name)
|
|
48
94
|
@name = name
|
|
49
95
|
end
|
|
50
96
|
end
|
|
51
97
|
|
|
52
98
|
# Request for an actor to terminate
|
|
53
|
-
class TerminationRequest < SystemEvent
|
|
99
|
+
class TerminationRequest < SystemEvent
|
|
100
|
+
handler do |event|
|
|
101
|
+
terminate
|
|
102
|
+
end
|
|
103
|
+
end
|
|
54
104
|
|
|
55
105
|
# Signal a condition
|
|
56
106
|
class SignalConditionRequest < SystemEvent
|
|
57
107
|
def initialize(task, value)
|
|
58
|
-
@task
|
|
108
|
+
@task = task
|
|
109
|
+
@value = value
|
|
59
110
|
end
|
|
60
111
|
attr_reader :task, :value
|
|
61
112
|
|
|
113
|
+
handler do |event|
|
|
114
|
+
event.call
|
|
115
|
+
end
|
|
116
|
+
|
|
62
117
|
def call
|
|
63
118
|
@task.resume(@value)
|
|
64
119
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Celluloid
|
|
2
|
+
class Task
|
|
3
|
+
# Tasks with a Fiber backend
|
|
4
|
+
class Fibered < Task
|
|
5
|
+
class StackError < Celluloid::Error; end
|
|
6
|
+
def create
|
|
7
|
+
queue = Thread.current[:celluloid_queue]
|
|
8
|
+
actor_system = Thread.current[:celluloid_actor_system]
|
|
9
|
+
@fiber = Fiber.new do
|
|
10
|
+
# FIXME: cannot use the writer as specs run inside normal Threads
|
|
11
|
+
Thread.current[:celluloid_role] = :actor
|
|
12
|
+
Thread.current[:celluloid_queue] = queue
|
|
13
|
+
Thread.current[:celluloid_actor_system] = actor_system
|
|
14
|
+
yield
|
|
15
|
+
# TODO: Determine why infinite thread leakage happens under jRuby, if `Fiber.yield` is used:
|
|
16
|
+
Fiber.yield unless RUBY_PLATFORM == "java"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def signal
|
|
21
|
+
Fiber.yield
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Resume a suspended task, giving it a value to return if needed
|
|
25
|
+
def deliver(value)
|
|
26
|
+
@fiber.resume value
|
|
27
|
+
rescue SystemStackError => ex
|
|
28
|
+
raise StackError, "#{ex} @#{meta[:method_name] || :unknown} (see https://github.com/celluloid/celluloid/wiki/Fiber-stack-errors)"
|
|
29
|
+
rescue FiberError => ex
|
|
30
|
+
raise DeadTaskError, "cannot resume a dead task (#{ex})"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Terminate this task
|
|
34
|
+
def terminate
|
|
35
|
+
super
|
|
36
|
+
rescue FiberError
|
|
37
|
+
# If we're getting this the task should already be dead
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def backtrace
|
|
41
|
+
["#{self.class} backtrace unavailable. Please try `Celluloid.task_class = Celluloid::Task::Threaded` if you need backtraces here."]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Celluloid
|
|
2
|
+
class Task
|
|
3
|
+
# Tasks with a Thread backend
|
|
4
|
+
class Threaded < Task
|
|
5
|
+
# Run the given block within a task
|
|
6
|
+
def initialize(type, meta)
|
|
7
|
+
@resume_queue = Queue.new
|
|
8
|
+
@exception_queue = Queue.new
|
|
9
|
+
@yield_mutex = Mutex.new
|
|
10
|
+
@yield_cond = ConditionVariable.new
|
|
11
|
+
@thread = nil
|
|
12
|
+
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create
|
|
17
|
+
# TODO: move this to ActorSystem#get_thread (ThreadHandle inside Group::Pool)
|
|
18
|
+
thread = Internals::ThreadHandle.new(Thread.current[:celluloid_actor_system], :task) do
|
|
19
|
+
begin
|
|
20
|
+
ex = @resume_queue.pop
|
|
21
|
+
fail ex if ex.is_a?(TaskTerminated)
|
|
22
|
+
|
|
23
|
+
yield
|
|
24
|
+
rescue ::Exception => ex
|
|
25
|
+
@exception_queue << ex
|
|
26
|
+
ensure
|
|
27
|
+
@yield_mutex.synchronize do
|
|
28
|
+
@yield_cond.signal
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
@thread = thread
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def signal
|
|
36
|
+
@yield_mutex.synchronize do
|
|
37
|
+
@yield_cond.signal
|
|
38
|
+
end
|
|
39
|
+
@resume_queue.pop
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def deliver(value)
|
|
43
|
+
fail DeadTaskError, "cannot resume a dead task" unless @thread.alive?
|
|
44
|
+
|
|
45
|
+
@yield_mutex.synchronize do
|
|
46
|
+
@resume_queue.push(value)
|
|
47
|
+
@yield_cond.wait(@yield_mutex)
|
|
48
|
+
fail @exception_queue.pop while @exception_queue.size > 0
|
|
49
|
+
end
|
|
50
|
+
rescue ThreadError
|
|
51
|
+
raise DeadTaskError, "cannot resume a dead task"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def backtrace
|
|
55
|
+
@thread.backtrace
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
module Celluloid
|
|
2
|
-
# Asked to do task-related things outside a task
|
|
3
|
-
class NotTaskError < Celluloid::Error; end
|
|
4
|
-
|
|
5
|
-
# Trying to resume a dead task
|
|
6
|
-
class DeadTaskError < Celluloid::Error; end
|
|
7
|
-
|
|
8
|
-
# Errors which should be resumed automatically
|
|
9
|
-
class ResumableError < Celluloid::Error; end
|
|
10
|
-
|
|
11
2
|
# Tasks are interruptable/resumable execution contexts used to run methods
|
|
12
3
|
class Task
|
|
13
|
-
class TerminatedError < ResumableError; end # kill a running task after terminate
|
|
14
|
-
|
|
15
|
-
class TimeoutError < ResumableError; end # kill a running task after timeout
|
|
16
|
-
|
|
17
4
|
# Obtain the current task
|
|
18
5
|
def self.current
|
|
19
|
-
Thread.current[:celluloid_task]
|
|
6
|
+
Thread.current[:celluloid_task] || fail(NotTaskError, "not within a task context")
|
|
20
7
|
end
|
|
21
8
|
|
|
22
9
|
# Suspend the running task, deferring to the scheduler
|
|
@@ -34,13 +21,13 @@ module Celluloid
|
|
|
34
21
|
@status = :new
|
|
35
22
|
|
|
36
23
|
@exclusive = false
|
|
37
|
-
@dangerous_suspend = @meta ? @meta.delete(:dangerous_suspend) : false
|
|
24
|
+
@dangerous_suspend = @meta ? @meta.dup.delete(:dangerous_suspend) : false
|
|
38
25
|
@guard_warnings = false
|
|
39
26
|
|
|
40
27
|
actor = Thread.current[:celluloid_actor]
|
|
41
|
-
@chain_id = CallChain.current_id
|
|
28
|
+
@chain_id = Internals::CallChain.current_id
|
|
42
29
|
|
|
43
|
-
|
|
30
|
+
fail NotActorError, "can't create tasks outside of actors" unless actor
|
|
44
31
|
guard "can't create tasks inside of tasks" if Thread.current[:celluloid_task]
|
|
45
32
|
|
|
46
33
|
create do
|
|
@@ -51,11 +38,11 @@ module Celluloid
|
|
|
51
38
|
name_current_thread thread_metadata
|
|
52
39
|
|
|
53
40
|
Thread.current[:celluloid_task] = self
|
|
54
|
-
CallChain.current_id = @chain_id
|
|
41
|
+
Internals::CallChain.current_id = @chain_id
|
|
55
42
|
|
|
56
43
|
actor.tasks << self
|
|
57
44
|
yield
|
|
58
|
-
rescue
|
|
45
|
+
rescue TaskTerminated
|
|
59
46
|
# Task was explicitly terminated
|
|
60
47
|
ensure
|
|
61
48
|
name_current_thread nil
|
|
@@ -65,19 +52,19 @@ module Celluloid
|
|
|
65
52
|
end
|
|
66
53
|
end
|
|
67
54
|
|
|
68
|
-
def create(&
|
|
69
|
-
|
|
55
|
+
def create(&_block)
|
|
56
|
+
fail "Implement #{self.class}#create"
|
|
70
57
|
end
|
|
71
58
|
|
|
72
59
|
# Suspend the current task, changing the status to the given argument
|
|
73
60
|
def suspend(status)
|
|
74
|
-
|
|
75
|
-
|
|
61
|
+
fail "Cannot suspend while in exclusive mode" if exclusive?
|
|
62
|
+
fail "Cannot suspend a task from outside of itself" unless Task.current == self
|
|
76
63
|
|
|
77
64
|
@status = status
|
|
78
65
|
|
|
79
66
|
if $CELLULOID_DEBUG && @dangerous_suspend
|
|
80
|
-
Logger.with_backtrace(caller[2...8]) do |logger|
|
|
67
|
+
Internals::Logger.with_backtrace(caller[2...8]) do |logger|
|
|
81
68
|
logger.warn "Dangerously suspending task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}"
|
|
82
69
|
end
|
|
83
70
|
end
|
|
@@ -85,15 +72,18 @@ module Celluloid
|
|
|
85
72
|
value = signal
|
|
86
73
|
|
|
87
74
|
@status = :running
|
|
88
|
-
|
|
89
|
-
|
|
75
|
+
fail value if value.is_a?(Celluloid::Interruption)
|
|
90
76
|
value
|
|
91
77
|
end
|
|
92
78
|
|
|
93
79
|
# Resume a suspended task, giving it a value to return if needed
|
|
94
80
|
def resume(value = nil)
|
|
95
81
|
guard "Cannot resume a task from inside of a task" if Thread.current[:celluloid_task]
|
|
96
|
-
|
|
82
|
+
if running?
|
|
83
|
+
deliver(value)
|
|
84
|
+
else
|
|
85
|
+
Internals::Logger.warn "Attempted to resume a dead task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}"
|
|
86
|
+
end
|
|
97
87
|
nil
|
|
98
88
|
end
|
|
99
89
|
|
|
@@ -113,17 +103,20 @@ module Celluloid
|
|
|
113
103
|
|
|
114
104
|
# Terminate this task
|
|
115
105
|
def terminate
|
|
116
|
-
|
|
106
|
+
fail "Cannot terminate an exclusive task" if exclusive?
|
|
117
107
|
|
|
118
108
|
if running?
|
|
119
|
-
|
|
120
|
-
|
|
109
|
+
if $CELLULOID_DEBUG
|
|
110
|
+
Internals::Logger.with_backtrace(backtrace) do |logger|
|
|
111
|
+
type = @dangerous_suspend ? :warn : :debug
|
|
112
|
+
logger.send(type, "Terminating task: type=#{@type.inspect}, meta=#{@meta.inspect}, status=#{@status.inspect}")
|
|
113
|
+
end
|
|
121
114
|
end
|
|
122
|
-
exception =
|
|
115
|
+
exception = TaskTerminated.new("task was terminated")
|
|
123
116
|
exception.set_backtrace(caller)
|
|
124
117
|
resume exception
|
|
125
118
|
else
|
|
126
|
-
|
|
119
|
+
fail DeadTaskError, "task is already dead"
|
|
127
120
|
end
|
|
128
121
|
end
|
|
129
122
|
|
|
@@ -136,7 +129,9 @@ module Celluloid
|
|
|
136
129
|
end
|
|
137
130
|
|
|
138
131
|
# Is the current task still running?
|
|
139
|
-
def running
|
|
132
|
+
def running?
|
|
133
|
+
@status != :dead
|
|
134
|
+
end
|
|
140
135
|
|
|
141
136
|
# Nicer string inspect for tasks
|
|
142
137
|
def inspect
|
|
@@ -145,9 +140,9 @@ module Celluloid
|
|
|
145
140
|
|
|
146
141
|
def guard(message)
|
|
147
142
|
if @guard_warnings
|
|
148
|
-
Logger.warn message if $CELLULOID_DEBUG
|
|
143
|
+
Internals::Logger.warn message if $CELLULOID_DEBUG
|
|
149
144
|
else
|
|
150
|
-
|
|
145
|
+
fail message if $CELLULOID_DEBUG
|
|
151
146
|
end
|
|
152
147
|
end
|
|
153
148
|
|
|
@@ -171,6 +166,3 @@ module Celluloid
|
|
|
171
166
|
end
|
|
172
167
|
end
|
|
173
168
|
end
|
|
174
|
-
|
|
175
|
-
require 'celluloid/tasks/task_fiber'
|
|
176
|
-
require 'celluloid/tasks/task_thread'
|
data/lib/celluloid/test.rb
CHANGED
data/lib/celluloid/thread.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "celluloid/fiber"
|
|
2
2
|
|
|
3
3
|
module Celluloid
|
|
4
4
|
class Thread < ::Thread
|
|
@@ -36,5 +36,10 @@ module Celluloid
|
|
|
36
36
|
def call_chain_id
|
|
37
37
|
self[:celluloid_chain_id]
|
|
38
38
|
end
|
|
39
|
+
|
|
40
|
+
def <<(proc)
|
|
41
|
+
self[:celluloid_queue] << proc
|
|
42
|
+
self
|
|
43
|
+
end
|
|
39
44
|
end
|
|
40
45
|
end
|