Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use StopIteration to stop Fiber for Playwright #111

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/charty/backends/plotly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,6 @@ def self.ensure_playwright
loop do
result = nil
case request.shift
when :finish
break
when :render
input, output, format, element_id, width, height = request

Expand All @@ -950,11 +948,14 @@ def self.ensure_playwright
kwargs = {type: format}
kwargs[:path] = output unless output.nil?
result = element.screenshot(**kwargs)
else
# Ignore unknown command
end
request = Fiber.yield(result)
end
end
end
@playwright_fiber = nil
end
@playwright_fiber.resume
end
Expand All @@ -963,10 +964,14 @@ def self.ensure_playwright
def self.terminate_playwright
return if @playwright_fiber.nil?

@playwright_fiber.resume([:finish])
@playwright_fiber.raise StopIteration
rescue FiberError
# Ignore FiberError
end

at_exit { terminate_playwright }
at_exit do
terminate_playwright
end

def self.render_image(input, output, format, element_id, width, height)
ensure_playwright if @playwright_fiber.nil?
Expand Down
Loading