forked from celluloid/dcell
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the Router to duck-type on the recipient to support Futures
- Loading branch information
Showing
4 changed files
with
52 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module DCell | ||
class Future | ||
def initialize(address,node_id,node_addr) | ||
@address = address | ||
@node_id = node_id | ||
@node_addr = node_addr | ||
end | ||
|
||
def <<(message) | ||
node = Node[@node_id] | ||
node = Node.new(@node_id, @node_addr) unless node | ||
node.send_message! Message::Relay.new(self, message) | ||
end | ||
|
||
def _dump(level) | ||
Marshal.dump [@address, @node_id, @node_addr] | ||
end | ||
|
||
# Loader for custom marshal format | ||
def self._load(string) | ||
address, node_id, node_addr = Marshal.load(string) | ||
if node_id == DCell.id | ||
Router.find(address) | ||
else | ||
new(address, node_id, node_addr) | ||
end | ||
end | ||
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
3220b31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is required to get the duck-typing functional.