[macruby-changes] [3450] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Mon Feb 8 15:04:45 PST 2010
Revision: 3450
http://trac.macosforge.org/projects/ruby/changeset/3450
Author: ernest.prabhakar at gmail.com
Date: 2010-02-08 15:04:45 -0800 (Mon, 08 Feb 2010)
Log Message:
-----------
Added Dispatch.label_for
Modified Paths:
--------------
MacRuby/trunk/lib/dispatch/dispatch.rb
MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb
Modified: MacRuby/trunk/lib/dispatch/dispatch.rb
===================================================================
--- MacRuby/trunk/lib/dispatch/dispatch.rb 2010-02-08 23:04:34 UTC (rev 3449)
+++ MacRuby/trunk/lib/dispatch/dispatch.rb 2010-02-08 23:04:45 UTC (rev 3450)
@@ -2,11 +2,17 @@
# directly from the top-level Dispatch module
module Dispatch
- # Returns a new serial queue with a unique label based on
- # the ancestor chain and ID of +obj+
+ # Returns a unique label based on the ancestor chain and ID of +obj+
+ # plus the current time
+ def label_for(obj)
+ label = obj.class.ancestors.uniq.reverse.join("_").downcase
+ now = Time.now.to_f.to_s.gsub(".","_")
+ "#{label}_%x_%s" % [obj.object_id, now]
+ end
+
+ # Returns a new serial queue with a unique label based on +obj+
def queue_for(obj)
- label = obj.class.ancestors.reverse.join(".").downcase
- Dispatch::Queue.new("#{label}.0x%x[#{obj}]" % obj.object_id)
+ Dispatch::Queue.new Dispatch.label_for(obj)
end
# Run the +&block+ synchronously on a concurrent queue
@@ -60,6 +66,6 @@
end
end
- module_function :queue_for, :async, :sync, :group, :wrap, :fork
+ module_function :label_for, :queue_for, :async, :sync, :group, :wrap, :fork
end
Modified: MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb 2010-02-08 23:04:34 UTC (rev 3449)
+++ MacRuby/trunk/spec/macruby/library/dispatch/dispatch_spec.rb 2010-02-08 23:04:45 UTC (rev 3450)
@@ -15,13 +15,19 @@
@actee = Actee.new("my_actee")
end
+ describe :label_for do
+ it "should return a unique label for any object" do
+ s1 = Dispatch.label_for(@actee)
+ s2 = Dispatch.label_for(@actee)
+ s1.should_not == s2
+ end
+ end
+
describe :queue_for do
- it "should return a unique label per actee" do
- s1 = Dispatch.queue_for(@actee).to_s
- s2 = Dispatch.queue_for(@actee).to_s
- s3 = Dispatch.queue_for(Actee.new("your_actee")).to_s
- s1.should == s2
- s1.should_not == s3
+ it "should return a unique queue" do
+ q1 = Dispatch.queue_for(@actee)
+ q2 = Dispatch.queue_for(@actee)
+ q1.should_not == q2
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100208/9498c298/attachment.html>
More information about the macruby-changes
mailing list