當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Ruby Timeout模塊用法及代碼示例

本文簡要介紹ruby語言中 Timeout模塊 的用法。

Timeout long-running 塊

概要

require 'timeout'
status = Timeout::timeout(5) {
  # Something that should be interrupted if it takes more than 5 seconds...
}

說明

Timeout 提供了一種方法來 auto-terminate 一個潛在的 long-running 操作,如果它沒有在固定的時間內完成。

以前的版本沒有使用命名空間模塊,但是提供 timeout 是為了向後兼容。你應該更喜歡 Timeout.timeout

版權

© 2000 Network Applied Communication Laboratory, Inc.

版權

© 2000 Information-technology 日本推廣署

相關用法


注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Timeout模塊。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。