Class: SlowLoadableComponent
Constant Summary
LoadableComponent::VERSION
Instance Method Summary
collapse
#load, #loaded?
Constructor Details
Returns a new instance of SlowLoadableComponent.
41
42
43
|
# File 'lib/loadable_component.rb', line 41
def initialize(timeout)
@timeout = timeout
end
|
Instance Method Details
#check_error ⇒ Object
Override this method to check for well-known error cases, which means loading has finished, but an error condition was seen.
69
70
71
|
# File 'lib/loadable_component.rb', line 69
def check_error
end
|
#get ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/loadable_component.rb', line 45
def get
if loaded?
return self
end
end_time = Time.now + @timeout
until Time.now >= end_time
return self if loaded?
check_error
sleep sleep_interval
end
unless loaded?
raise UnableToLoadComponent, unable_to_load_message
end
self
end
|
#sleep_interval ⇒ Object
73
74
75
|
# File 'lib/loadable_component.rb', line 73
def sleep_interval
0.2
end
|
#unable_to_load_message ⇒ Object
77
78
79
|
# File 'lib/loadable_component.rb', line 77
def unable_to_load_message
"#{super} after #{@timeout} seconds"
end
|