我尝试使用concurrent-ruby来完成一些并行任务,我遵循文档并使用Concurrent::Async
:
require 'concurrent'
class Echo
include Concurrent::Async
def echo(msg)
p msg
end
end
horn = Echo.new
horn.async.echo('one')
并在终端中运行它,但是过程什么也没打印,然后立即退出
答案 0 :(得分:1)
require 'concurrent'
class Echo
include Concurrent::Async
def echo(msg)
p msg
end
end
horn = Echo.new
# t is an instance of Concurrent::IVar which includes Concurrent::Concern::Obligation
t = horn.async.echo('one')
# wait until obligation is complete or the timeout has been reached
t.wait!