mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* sample/timeout.rb: split from lib/timeout.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26877 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ebfe278914
commit
831eb93069
4 changed files with 48 additions and 23 deletions
|
@ -1,3 +1,7 @@
|
|||
Fri Mar 12 06:37:13 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* sample/timeout.rb: split from lib/timeout.rb.
|
||||
|
||||
Thu Mar 11 22:35:27 2010 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* time.c (time_round): new method Time#round. [ruby-dev:40595]
|
||||
|
|
|
@ -85,24 +85,3 @@ end
|
|||
# Another name for Timeout::Error, defined for backwards compatibility with
|
||||
# earlier versions of timeout.rb.
|
||||
TimeoutError = Timeout::Error
|
||||
|
||||
if __FILE__ == $0
|
||||
p timeout(5) {
|
||||
45
|
||||
}
|
||||
p timeout(5, TimeoutError) {
|
||||
45
|
||||
}
|
||||
p timeout(nil) {
|
||||
54
|
||||
}
|
||||
p timeout(0) {
|
||||
54
|
||||
}
|
||||
p timeout(5) {
|
||||
loop {
|
||||
p 10
|
||||
sleep 1
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
42
sample/timeout.rb
Normal file
42
sample/timeout.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'timeout'
|
||||
|
||||
def progress(n = 5)
|
||||
n.times {|i| print i; STDOUT.flush; sleep 1; i+= 1}
|
||||
puts "never reach"
|
||||
end
|
||||
|
||||
p timeout(5) {
|
||||
45
|
||||
}
|
||||
p timeout(5, TimeoutError) {
|
||||
45
|
||||
}
|
||||
p timeout(nil) {
|
||||
54
|
||||
}
|
||||
p timeout(0) {
|
||||
54
|
||||
}
|
||||
begin
|
||||
timeout(5) {progress}
|
||||
rescue => e
|
||||
puts e.message
|
||||
end
|
||||
begin
|
||||
timeout(3) {
|
||||
begin
|
||||
timeout(5) {progress}
|
||||
rescue => e
|
||||
puts "never reach"
|
||||
end
|
||||
}
|
||||
rescue => e
|
||||
puts e.message
|
||||
end
|
||||
class MyTimeout < StandardError
|
||||
end
|
||||
begin
|
||||
timeout(2, MyTimeout) {progress}
|
||||
rescue MyTimeout => e
|
||||
puts e.message
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
#define RUBY_VERSION "1.9.2"
|
||||
#define RUBY_RELEASE_DATE "2010-03-11"
|
||||
#define RUBY_RELEASE_DATE "2010-03-12"
|
||||
#define RUBY_PATCHLEVEL -1
|
||||
#define RUBY_BRANCH_NAME "trunk"
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
|||
#define RUBY_VERSION_TEENY 1
|
||||
#define RUBY_RELEASE_YEAR 2010
|
||||
#define RUBY_RELEASE_MONTH 3
|
||||
#define RUBY_RELEASE_DAY 11
|
||||
#define RUBY_RELEASE_DAY 12
|
||||
|
||||
#include "ruby/version.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue