From 036c38ab7b16c2075dbf64eb02780a7ad1356f5e Mon Sep 17 00:00:00 2001 From: Joel Drapper Date: Tue, 26 Nov 2024 12:28:00 +0000 Subject: [PATCH] Remove `await` --- lib/phlex/sgml.rb | 13 ------ quickdraw/sgml/await.test.rb | 85 ------------------------------------ 2 files changed, 98 deletions(-) delete mode 100644 quickdraw/sgml/await.test.rb diff --git a/lib/phlex/sgml.rb b/lib/phlex/sgml.rb index 51fbbfb7..d1ce917b 100644 --- a/lib/phlex/sgml.rb +++ b/lib/phlex/sgml.rb @@ -50,19 +50,6 @@ def view_template end end - def await(task) - case task - when defined?(Concurrent::IVar) && Concurrent::IVar - flush if task.pending? - task.wait.value - when defined?(Async::Task) && Async::Task - flush if task.running? - task.wait - else - raise Phlex::ArgumentError.new("Expected an asynchronous task / promise.") - end - end - def to_proc proc { |c| c.render(self) } end diff --git a/quickdraw/sgml/await.test.rb b/quickdraw/sgml/await.test.rb deleted file mode 100644 index 97574347..00000000 --- a/quickdraw/sgml/await.test.rb +++ /dev/null @@ -1,85 +0,0 @@ -# frozen_string_literal: true - -class Example < Phlex::HTML - def initialize(task) - @task = task - end - - def view_template - h1 { "Before" } - - await(@task).then do |message| - h1 { message } - end - - h1 { "After" } - end -end - -test "when given a non async task" do - expect { Example.new("Hello").call }.to_raise(Phlex::ArgumentError) do |error| - expect(error.message) == "Expected an asynchronous task / promise." - end -end - -test "async task flushes when waiting" do - pid = Process.fork do - require "async" - - Sync do - task = Async { sleep 0.01; "Hello" } - buffer = [] - Example.new(task).call(buffer) - buffer => ["

Before

", "

Hello

After

"] - end - end - - pid, result = Process.wait2(pid) - - assert result.success? -end - -test "async task doesn't flush when it doesn't need to wait" do - pid = Process.fork do - require "async" - - Sync do - task = Async { sleep 0.01; "Hello" } - task.wait - buffer = [] - Example.new(task).call(buffer) - buffer => ["

Before

Hello

After

"] - end - end - - pid, result = Process.wait2(pid) - - assert result.success? -end - -test "concurrent promise flushes when waiting" do - pid = Process.fork do - require "concurrent" - task = Concurrent::Promise.execute { sleep 0.01; "Hello" } - buffer = [] - Example.new(task).call(buffer) - buffer => ["

Before

", "

Hello

After

"] - end - - pid, result = Process.wait2(pid) - assert result.success? -end - -test "concurrent promise doesn't flush when it doesn't need to wait" do - pid = Process.fork do - require "concurrent" - task = Concurrent::Promise.execute { sleep 0.01; "Hello" } - task.wait - buffer = [] - Example.new(task).call(buffer) - buffer => ["

Before

Hello

After

"] - end - - pid, result = Process.wait2(pid) - assert result.success? -end