开发者

Rufus::Scheduler join can not exit at last in ruby

i use Rufus::Scheduler to schedule a task, the code is listed bel开发者_JAVA技巧ow:

class Scheduler
  def self.run
    scheduler = Rufus::Scheduler.start_new
    job = scheduler.in '5s', A.new
    scheduler.join
  end
  class A
    def call(job)
      puts "xxxxxx"
    end
  end
end
Scheduler.run

after running the code, it has print 'xxxx', but after running the call method, the join can not exit by itself and always hang-up.

is there some way to exit the join after waiting to finish the job? thank u.


The scheduler is meant to run "forever". Calling "join" joins the scheduler thread and only exits when the thread dies.

You should reconsider your code, you're trying to use a hammer like a screwdriver.


Use plain Thread can reach the requirement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜