Permalink
Browse files

Simple use of agent to cap or originate routes.

  • Loading branch information...
1 parent 8c8f9a6 commit ed4b4ff7c4c43a67e8daf3ccb3043a6e880c3b26 Darrick Wiebe committed Mar 30, 2011
Showing with 51 additions and 0 deletions.
  1. +51 −0 lib/pacer-agent.rb
View
@@ -0,0 +1,51 @@
+require 'agent'
+
+module Pacer
+ module Core
+ module Route
+ def channel(opts = {})
+ name = (inspect_strings + [hash]).join('_').gsub(/\W/, '_').to_sym
+ opts = {
+ :name => name,
+ :type => element_type,
+ :limit => 1
+ }.merge(opts)
+ channel = Agent::Channel.new opts
+ go(channel, self) do |c, r|
+ r.each do |elem|
+ c << elem
+ end
+ c << c
+ end
+ channel
+ end
+ end
+ end
+end
+
+module Agent
+ class Channel
+ include Enumerable
+
+ def to_route
+ r = Pacer::Route.new :source => self, :element_type => Object, :route_name => "|#{ name }|"
+ r.route
+ end
+
+ def each
+ return to_enum unless block_given?
+ while not closed?
+ value = receive
+ return close if self == value
+ yield value
+ end
+ end
+
+ def ==(other)
+ other.is_a?(Channel) and
+ other.name == name and
+ other.type == type and
+ other.instance_variable_get('@direction') == @direction
+ end
+ end
+end

0 comments on commit ed4b4ff

Please sign in to comment.