Skip to content

Commit

Permalink
Add fiber isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldrapper committed Nov 26, 2024
1 parent 2484d5b commit c21d941
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/phlex/kit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def const_added(name)
end

define_singleton_method(name) do |*args, **kwargs, &block|
if (component = Thread.current[:__phlex_component__])
component, fiber_id = Thread.current[:__phlex_component__]
if (component && fiber_id == Fiber.current.object_id)
component.instance_exec do
constant = me.const_get(name)
render(constant.new(*args, **kwargs), &block)
Expand Down
4 changes: 2 additions & 2 deletions lib/phlex/sgml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def call(buffer = +"", context: {}, view_context: nil, parent: nil, fragments: n

return "" unless render?

Thread.current[:__phlex_component__] = self
Thread.current[:__phlex_component__] = [self, Fiber.current.object_id]

phlex_context.around_render do
before_template(&block)
Expand All @@ -96,7 +96,7 @@ def call(buffer = +"", context: {}, view_context: nil, parent: nil, fragments: n
buffer << phlex_context.buffer
end
ensure
Thread.current[:__phlex_component__] = parent
Thread.current[:__phlex_component__] = [parent, Fiber.current.object_id]
end

protected def __context__ = @_context
Expand Down

0 comments on commit c21d941

Please sign in to comment.