[macruby-changes] [3365] MacRuby/trunk/lib/dispatch/futures.rb
source_changes at macosforge.org
source_changes at macosforge.org
Fri Jan 29 15:40:06 PST 2010
Revision: 3365
http://trac.macosforge.org/projects/ruby/changeset/3365
Author: ernest.prabhakar at gmail.com
Date: 2010-01-29 15:40:06 -0800 (Fri, 29 Jan 2010)
Log Message:
-----------
Redid Futures to use Dispatch helper methods
Modified Paths:
--------------
MacRuby/trunk/lib/dispatch/futures.rb
Modified: MacRuby/trunk/lib/dispatch/futures.rb
===================================================================
--- MacRuby/trunk/lib/dispatch/futures.rb 2010-01-29 23:40:04 UTC (rev 3364)
+++ MacRuby/trunk/lib/dispatch/futures.rb 2010-01-29 23:40:06 UTC (rev 3365)
@@ -4,21 +4,18 @@
# Create a future that asynchronously dispatches the block
# to a concurrent queue of the specified (optional) +priority+
def initialize(priority=nil, &block)
- @group = Group.new
@value = nil
- Dispatch.group(@group, priority) { @value = block.call }
+ @group = Dispatch.fork(priority) { @value = block.call }
end
# Waits for the computation to finish, then returns the value
# Duck-typed to lambda.call(void)
- def call()
- @group.wait
- @value
- end
-
- # Passes the value to the +callback+ block when it is available
- # Duck-typed to group.notify(&block)
- def notify(&callback)
+ # If a block is passed, invoke that asynchronously with the final value
+ def call(&callback)
+ if not block_given?
+ @group.wait
+ return @value
+ end
@group.notify { callback.call(@value) }
end
end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100129/0b7648f3/attachment-0001.html>
More information about the macruby-changes
mailing list