Module: AsyncRender::Warmup
Constant Summary collapse
- POOL =
AsyncRender.executor
Instance Method Summary collapse
-
#warmup_render(partial, locals = {}) ⇒ Object
Queue an async render for a partial so views can reference it via placeholders.
Methods included from Utils
#build_memoized_render_key, #generate_token, #normalize_locals
Instance Method Details
#warmup_render(partial, locals = {}) ⇒ Object
Queue an async render for a partial so views can reference it via placeholders. The result is stitched into the HTML by the middleware.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/async_render/warmup.rb', line 29 def warmup_render(partial, locals = {}) return unless AsyncRender.enabled AsyncRender::Current.skip_middleware = false warmup_key = build_memoized_render_key(partial, locals) placeholder = AsyncRender::Current.warmup_partials[warmup_key] return placeholder if placeholder token = generate_token(partial) placeholder = (AsyncRender::PLACEHOLDER_TEMPLATE % token).html_safe state = AsyncRender.dump_state_proc&.call AsyncRender::Current.warmup_partials[warmup_key] = placeholder AsyncRender::Current.async_futures[token] = Concurrent::Promises.future_on(POOL) do AsyncRender::Executor.new(partial:, locals:, state:).call end placeholder end |