开发者

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

开发者 https://www.devze.com 2023-02-04 12:51 出处:网络
i use Rufus::Scheduler to schedule a task, the code is listed bel开发者_JAVA技巧ow: class Scheduler

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

精彩评论

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

关注公众号