async
async copied to clipboard
NoMethodError: undefined method `wait_any' for #<IO:fd 11>
Hi, When I tried to run this, I got NoMethodError: undefined method `wait_any'...
require 'db/client'
require 'db/postgres'
client = DB::Client.new(DB::Postgres::Adapter.new(database: 'test'))
def create_schema(session)
session.clause("DROP TABLE IF EXISTS").identifier(:things).call
session.clause("CREATE TABLE IF NOT EXISTS")
.identifier(:things)
.clause("(")
# .identifier(:id).clause("BIGSERIAL PRIMARY KEY,")
.identifier(:low).clause("INT NOT NULL,")
.identifier(:high).clause("INT NOT NULL")
.clause(")").call
#session.clause("SET default_statistics_target=10000;").call
#session.clause("CREATE STATISTICS low_high_statistics (dependencies) ON low, high FROM things;").call
end
def create_data(session)
million = (0...1_000_000).to_a
rows = {
5 => million.dup,
10 => million.dup,
15 => million.dup,
20 => million.dup,
25 => million.dup,
30 => million.dup,
35 => million.dup,
40 => million.dup,
45 => million.dup,
50 => million.dup,
}
rows.each do |low, values|
insert = session.clause("INSERT INTO").identifier(:things)
.clause("(")
.identifier(:low).clause(",")
.identifier(:high)
.clause(")")
.clause("VALUES")
while high = values.pop
insert.clause("(")
.literal(low).clause(",")
.literal(high)
if values.empty?
insert.clause(")")
else
insert.clause("),")
end
end
insert.call
end
end
Async do |task|
session = client.session
create_schema(session)
task.async do
session = client.session
create_data(session)
end
task.async do
session = client.session
result = session.query("select low, high from things").call.to_a
end
end
Error is in line 67 of wrapper.rb
# Wait fo the io to become either readable or writable.
# @parameter duration [Float] timeout after the given duration if not `nil`.
def wait_any(timeout = @timeout)
@io.wait_any(timeout) or raise TimeoutError
end
During debug I didn't find wait_any method, but there was wait one. When I fixed it to
@io.wait(timeout) or raise TimeoutError
I got #TypeError: can't convert NilClass into time interval
I will check what's going on.
https://www.rubydoc.info/gems/async/1.28.9/Async%2FWrapper:wait_any
However, this might have changed in Async 2.0 - I'm still working through the entire eco-system and updating components.
I checked and this problem appears to have been fixed in Async 2+.