Belajar Pemrograman Ruby: Timeout

Timeout merupakan modul yang digunakan untuk mengatur timing program.

Contoh 1

require 'timeout'

begin
	Timeout::timeout(3) do 
		sleep(5)
		puts "Jika lewat 3 detik program ini akan dilempar ke pesan error"
	end
	rescue Timeout::Error
  		puts 'Pesan error'
end

Output

Pesan Error

Contoh 2

require 'timeout'

begin
	Timeout::timeout(3) do 
		puts "Jika lewat 3 detik program ini akan dilempar ke pesan error"
	end
	rescue Timeout::Error
  		puts 'Pesan error'
end

Output

Jika lewat 3 detik program ini akan dilempar ke pesan error

Keep Fun Coding 😀

Advertisements

One thought on “Belajar Pemrograman Ruby: Timeout

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s