Module: SlowLoadableComponent
Constant Summary
LoadableComponent::VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
#load, #loaded?
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
42
43
44
|
# File 'lib/loadable_component.rb', line 42
def 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.
72
73
74
|
# File 'lib/loadable_component.rb', line 72
def check_error
end
|
#get ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/loadable_component.rb', line 44
def get
if loaded?
return self
end
load
end_time = Time.now
end_time += @timeout if @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
76
77
78
|
# File 'lib/loadable_component.rb', line 76
def sleep_interval
0.2
end
|
#unable_to_load_message ⇒ Object
80
81
82
|
# File 'lib/loadable_component.rb', line 80
def unable_to_load_message
"#{super} after #{@timeout} seconds"
end
|