lib/dharma.rb in dharma-0.9.0 vs lib/dharma.rb in dharma-0.9.1
- old
+ new
@@ -1,11 +1,12 @@
module Dharma
- VERSION = '0.9.0'
+ VERSION = '0.9.1'
class PromiseFailure < RuntimeError; end
class IllegalStateException < RuntimeError; end
class TimeoutException < RuntimeError; end
+ class NoSuchElementException < RuntimeError; end
def self.default_executor
@default_executor ||= Dharma::ThreadExecutor.new
end
@@ -29,13 +30,31 @@
future do
promises.map { |p| p.result }
end
end
+ def self.first_completed_of(promises)
+ p = Dharma.promise
+ promises.each do |promies|
+ promise.on_complete do |value, as|
+ p.try_complete(value, as)
+ end
+ end
+ p
+ end
+
def self.trace_completion(tag, promise, logger = Rails.logger)
promise.on_complete do |value, as|
logger.info "#{tag}: #{as}: #{value.inspect}"
end
+ end
+
+ def self.ready(promise, duration = nil)
+ promise.ready(duration)
+ end
+
+ def self.result(promise, duration = nil)
+ promise.result(duration)
end
end
require 'dharma/promise'
require 'dharma/future'
\ No newline at end of file