Class: ReactOnRailsPro::AsyncValue
- Inherits:
-
Object
- Object
- ReactOnRailsPro::AsyncValue
- Defined in:
- lib/react_on_rails_pro/async_value.rb
Overview
AsyncValue wraps an Async task to provide a simple interface for retrieving the result of an async react_component render.
Instance Method Summary collapse
- #html_safe ⇒ Object
-
#initialize(task:) ⇒ AsyncValue
constructor
A new instance of AsyncValue.
- #resolved? ⇒ Boolean
- #to_s ⇒ Object
-
#value ⇒ Object
Blocks until result is ready, returns HTML string.
Constructor Details
#initialize(task:) ⇒ AsyncValue
Returns a new instance of AsyncValue.
26 27 28 |
# File 'lib/react_on_rails_pro/async_value.rb', line 26 def initialize(task:) @task = task end |
Instance Method Details
#html_safe ⇒ Object
44 45 46 |
# File 'lib/react_on_rails_pro/async_value.rb', line 44 def html_safe value.html_safe end |
#resolved? ⇒ Boolean
36 37 38 |
# File 'lib/react_on_rails_pro/async_value.rb', line 36 def resolved? @task.finished? end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/react_on_rails_pro/async_value.rb', line 40 def to_s value.to_s end |
#value ⇒ Object
Blocks until result is ready, returns HTML string. If the async task raised an exception, it will be re-raised here.
32 33 34 |
# File 'lib/react_on_rails_pro/async_value.rb', line 32 def value @task.wait end |