救援行动
拯救/重试一个块,最多多次。
安装
将此行添加到应用程序的 Gemfile 中:
gem 'rescue_up_to'
然后执行:
$ bundle
或者自己安装:
$ gem install rescue_up_to
用法
# Rescue / retry something, up to 10 times
value = rescue_up_to(10.times) do
# do something, rescue StandardError and retry up to 10 times ...
end
# A more complex / useful example, fetch Google's home page
require 'open-uri'
contents = rescue_up_to(10.times, from: SocketE
评论0
最新资源