Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #643 from celluloid/0.17.5-release
Update GSoC branch.
- Loading branch information
Showing
26 changed files
with
359 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$:.push File.expand_path('../../lib', __FILE__) | ||
require 'celluloid/autostart' | ||
|
||
# This example builds on basic_usage.rb to show two things about #async: the | ||
# (new) fluent API and the preservation of causality order. | ||
class Stack | ||
include Celluloid | ||
|
||
attr_reader :ary | ||
|
||
def initialize | ||
@ary = [] | ||
end | ||
|
||
def push x | ||
@ary.push x | ||
end | ||
alias << push | ||
|
||
def pop | ||
@ary.pop | ||
end | ||
|
||
def show | ||
p @ary | ||
end | ||
end | ||
|
||
st = Stack.new | ||
|
||
# Schedule three calls to #push some integers on the stack. They will execute | ||
# in order because the calls originated as a sequence of method calls in a | ||
# single thread. | ||
st.async << 1 << 2 << 3 | ||
|
||
# Schedule a call to show the stack after the three push calls execute. | ||
st.async.show | ||
|
||
# Schedule three calls to #pop from the stack. | ||
st.async.pop.pop.pop | ||
|
||
# The next (non-async) call is guaranteed to execute after methods previously | ||
# scheduled in this thread. The causal order of calls (order as requested) is | ||
# preserved in the execution order. | ||
st.show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
$CELLULOID_BACKPORTED = :silently | ||
$CELLULOID_BACKPORTED = true | ||
require "celluloid/autostart" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
module Celluloid | ||
module Proxy | ||
# Base class of all Celluloid proxies | ||
class Abstract < BasicObject | ||
# Used for reflecting on proxy objects themselves | ||
def __class__ | ||
Proxy::Abstract | ||
end | ||
|
||
# Needed for storing proxies in data structures | ||
needed = [:object_id, :__id__, :hash, :private_methods] - instance_methods | ||
if needed.any? | ||
include ::Kernel.dup.module_eval { | ||
undef_method(*(instance_methods - needed)) | ||
self | ||
} | ||
# Base class of Celluloid proxies | ||
class Celluloid::Proxy::Abstract < BasicObject | ||
# Used for reflecting on proxy objects themselves | ||
def __class__ | ||
::Celluloid::Proxy::Abstract | ||
end | ||
|
||
# rubinius bug? These methods disappear when we include hacked kernel | ||
define_method :==, ::BasicObject.instance_method(:==) unless instance_methods.include?(:==) | ||
alias_method(:equal?, :==) unless instance_methods.include?(:equal?) | ||
end | ||
end | ||
# Needed for storing proxies in data structures | ||
needed = [:object_id, :__id__, :hash, :private_methods] - instance_methods | ||
if needed.any? | ||
include ::Kernel.dup.module_eval { | ||
undef_method(*(instance_methods - needed)) | ||
self | ||
} | ||
# rubinius bug? These methods disappear when we include hacked kernel | ||
define_method :==, ::BasicObject.instance_method(:==) unless instance_methods.include?(:==) | ||
alias_method(:equal?, :==) unless instance_methods.include?(:equal?) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,41 @@ | ||
module Celluloid | ||
module Proxy | ||
# A proxy which controls the Actor lifecycle | ||
class Actor < Abstract | ||
attr_reader :thread, :mailbox | ||
# A proxy which controls the Actor lifecycle | ||
class Celluloid::Proxy::Actor < Celluloid::Proxy::Abstract | ||
attr_reader :thread, :mailbox | ||
|
||
# Used for reflecting on proxy objects themselves | ||
def __class__ | ||
Proxy::Actor | ||
end | ||
# Used for reflecting on proxy objects themselves | ||
def __class__ | ||
::Celluloid::Proxy::Actor | ||
end | ||
|
||
def initialize(thread, mailbox) | ||
@thread = thread | ||
@mailbox = mailbox | ||
end | ||
def initialize(mailbox, thread) | ||
@mailbox, @thread = mailbox, thread | ||
end | ||
|
||
def inspect | ||
# TODO: use a system event to fetch actor state: tasks? | ||
"#<Celluloid::Proxy::Actor(#{@mailbox.address}) alive>" | ||
rescue DeadActorError | ||
"#<Celluloid::Proxy::Actor(#{@mailbox.address}) dead>" | ||
end | ||
def inspect | ||
# TODO: use a system event to fetch actor state: tasks? | ||
"#<::Celluloid::Proxy::Actor(#{@mailbox.address}) alive>" | ||
rescue DeadActorError | ||
"#<::Celluloid::Proxy::Actor(#{@mailbox.address}) dead>" | ||
end | ||
|
||
def alive? | ||
@mailbox.alive? | ||
end | ||
def alive? | ||
@mailbox.alive? | ||
end | ||
|
||
def dead? | ||
!alive? | ||
end | ||
def dead? | ||
!alive? | ||
end | ||
|
||
# Terminate the associated actor | ||
def terminate | ||
terminate! | ||
::Celluloid::Actor.join(self) | ||
nil | ||
end | ||
# Terminate the associated actor | ||
def terminate | ||
terminate! | ||
::Celluloid::Actor.join(self) | ||
nil | ||
end | ||
|
||
# Terminate the associated actor asynchronously | ||
def terminate! | ||
::Kernel.raise DeadActorError, "actor already terminated" unless alive? | ||
@mailbox << TerminationRequest.new | ||
end | ||
end | ||
# Terminate the associated actor asynchronously | ||
def terminate! | ||
::Kernel.raise ::Celluloid::DeadActorError, "actor already terminated" unless alive? | ||
@mailbox << ::Celluloid::TerminationRequest.new | ||
end | ||
end |
Oops, something went wrong.