From 7ad09105d1095627a71380d989f51a4a1a59bbf6 Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Tue, 28 May 2024 10:44:45 +0900 Subject: [PATCH] Use StopIteration to stop Fiber for Playwright --- lib/charty/backends/plotly.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/charty/backends/plotly.rb b/lib/charty/backends/plotly.rb index 06875031..5969ce2f 100644 --- a/lib/charty/backends/plotly.rb +++ b/lib/charty/backends/plotly.rb @@ -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 @@ -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 @@ -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?