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.
13 14 15 |
# File 'lib/react_on_rails_pro/async_value.rb', line 13 def initialize(task:) @task = task end |
Instance Method Details
#html_safe ⇒ Object
31 32 33 |
# File 'lib/react_on_rails_pro/async_value.rb', line 31 def html_safe value.html_safe end |
#resolved? ⇒ Boolean
23 24 25 |
# File 'lib/react_on_rails_pro/async_value.rb', line 23 def resolved? @task.finished? end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/react_on_rails_pro/async_value.rb', line 27 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.
19 20 21 |
# File 'lib/react_on_rails_pro/async_value.rb', line 19 def value @task.wait end |