Sha256: 754a82e2f052d2c3cc5aa048ec6d67f0405b48c827a9dba805b7afe9e1bf9303
Contents?: true
Size: 1.38 KB
Versions: 1
Compression:
Stored size: 1.38 KB
Contents
require 'java' require_relative 'j_future/version' require_relative 'j_future/callable' require_relative 'j_future/daemon_thread_factory' require_relative 'j_future/executor_factory' class JFuture < ::BasicObject MILLIS = ::Java::JavaUtilConcurrent::TimeUnit::MILLISECONDS METHODS = [:is_done?, :on_complete] def initialize(executor: :default, access_timeout_millis: nil, arg: nil, &block) @access_timeout_millis = access_timeout_millis callable = Callable.new(arg, &block) if (executor.is_a? ::Java::JavaUtilConcurrent::AbstractExecutorService) @executor = executor else @executor = ExecutorFactory.get_executor(executor) end @future = @executor.submit callable end def respond_to?(id, *args) return true if METHODS.include?(id) if @access_timeout_millis.nil? @future.get.respond_to?(id, *args) else @future.get(@access_timeout_millis.to_i, MILLIS).respond_to?(id, *args) end end def is_done? @future.isDone end def on_complete(executor: :default, access_timeout_millis: nil, &block) ::JFuture.new(executor: executor, access_timeout_millis: access_timeout_millis, arg: self, &block) end def method_missing(name, *args, &block) if @access_timeout_millis.nil? @future.get.send(name, *args, &block) else @future.get(@access_timeout_millis.to_i, MILLIS).send(name, *args, &block) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
j_future-0.0.2-java | lib/j_future.rb |