summaryrefslogtreecommitdiff
path: root/jni/ruby/sample/timeout.rb
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/sample/timeout.rb
Fresh start
Diffstat (limited to 'jni/ruby/sample/timeout.rb')
-rw-r--r--jni/ruby/sample/timeout.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/jni/ruby/sample/timeout.rb b/jni/ruby/sample/timeout.rb
new file mode 100644
index 0000000..8d25d72
--- /dev/null
+++ b/jni/ruby/sample/timeout.rb
@@ -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, Timeout::Error) {
+ 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