[macruby-changes] [3613] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 24 17:39:00 PST 2010
Revision: 3613
http://trac.macosforge.org/projects/ruby/changeset/3613
Author: ernest.prabhakar at gmail.com
Date: 2010-02-24 17:38:57 -0800 (Wed, 24 Feb 2010)
Log Message:
-----------
Simplify Dispatch::Source API further
Modified Paths:
--------------
MacRuby/trunk/lib/dispatch/README.rdoc
MacRuby/trunk/lib/dispatch/source.rb
MacRuby/trunk/spec/macruby/library/dispatch/source_spec.rb
Modified: MacRuby/trunk/lib/dispatch/README.rdoc
===================================================================
--- MacRuby/trunk/lib/dispatch/README.rdoc 2010-02-25 00:37:51 UTC (rev 3612)
+++ MacRuby/trunk/lib/dispatch/README.rdoc 2010-02-25 01:38:57 UTC (rev 3613)
@@ -242,7 +242,6 @@
(0..4).p_findall(3) { |i| i.odd?} # => 3
-
== Dispatch::Sources: Asynchronous Events
In addition to scheduling blocks directly, GCD makes it easy to run a block in response to various system events via a Dispatch::Source, which supports:
Modified: MacRuby/trunk/lib/dispatch/source.rb
===================================================================
--- MacRuby/trunk/lib/dispatch/source.rb 2010-02-25 00:37:51 UTC (rev 3612)
+++ MacRuby/trunk/lib/dispatch/source.rb 2010-02-25 01:38:57 UTC (rev 3613)
@@ -3,14 +3,14 @@
module Dispatch
class Source
- @@procs = {
+ @@proc_event = {
exit:PROC_EXIT,
fork:PROC_FORK,
exec:PROC_EXEC,
signal:PROC_SIGNAL
}
- @@vnodes = {
+ @@vnode_event = {
delete:VNODE_DELETE,
write:VNODE_WRITE,
extend:VNODE_EXTEND,
@@ -22,25 +22,19 @@
class << self
- def proc(e)
- convert(e, @@procs)
- end
-
- def vnode(e)
- convert(e, @@vnodes)
- end
+ def event(e)
+ convert(e, @@proc_event) || convert(e, @@vnode_event)
+ end
def events2mask(events, hash)
mask = events.collect { |e| convert(e, hash) }.reduce(:|)
end
def convert(e, hash)
- return e.to_i if e.is_a? Numeric
- value = hash[e.to_sym]
+ value = e.to_int rescue hash[e.to_sym]
raise ArgumentError, "No event type #{e.inspect}" if value.nil?
value
end
-
# Returns Dispatch::Source of type DATA_ADD
def add(queue = Dispatch::Queue.concurrent, &block)
Modified: MacRuby/trunk/spec/macruby/library/dispatch/source_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/library/dispatch/source_spec.rb 2010-02-25 00:37:51 UTC (rev 3612)
+++ MacRuby/trunk/spec/macruby/library/dispatch/source_spec.rb 2010-02-25 01:38:57 UTC (rev 3613)
@@ -47,7 +47,7 @@
Process.kill(@signal, $$)
Signal.trap(@signal, "DEFAULT")
@q.sync {}
- (@event & Dispatch::Source.proc(:signal)).should > 0
+ (@event & Dispatch::Source.event(:signal)).should > 0
end
end
@@ -126,7 +126,7 @@
@q.sync { }
#while (@fired == false) do; end
@fired.should == true
- @flag.should == Dispatch::Source.vnode(:write)
+ @flag.should == Dispatch::Source.event(:write)
end
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100224/bc7e8feb/attachment.html>
More information about the macruby-changes
mailing list