Sha256: df88522052a51c97c93536741ffed603f7d2cb93d172c55ee0da1080a78c09be
Contents?: true
Size: 389 Bytes
Versions: 7
Compression:
Stored size: 389 Bytes
Contents
require 'thread' module Concurrent TimeoutError = Class.new(StandardError) def timeout(seconds) thread = Thread.new do Thread.current[:result] = yield end success = thread.join(seconds) if success return thread[:result] else raise TimeoutError end ensure Thread.kill(thread) unless thread.nil? end module_function :timeout end
Version data entries
7 entries across 7 versions & 1 rubygems