Async task is appears to be blocking #364
-
I'm trying to run a really simple test: require "async"
describe "async" do
it "tests async" do
task = Async do
sleep(100)
end
task.stop
puts "done"
end
end This should return instantly right? why does the test take 100sec to run? i'm sorry if this is really obvious im on:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
A top level async task is blocking as there is no way the sleep can execute while continuing to execute the code outside the event loop. You should run your entire test inside an event, e.g. require "async"
describe "async" do
it "tests async" do
Async do
task = Async do
sleep(100)
end
task.stop
puts "done"
end
end
end If you are using Sus you can use require "async"
require "sus/fixtures/async"
describe "async" do
include Sus::Fixtures::Async::ReactorContext
it "tests async" do
task = Async do
sleep(100)
end
task.stop
puts "done"
end
end The reactor context also adds a 60s timeout to the code to ensure your tests aren't hanging. |
Beta Was this translation helpful? Give feedback.
-
I see. i missed that in the docs: unrelated but @ioquatix thats literally the fastest non-automated response i've ever seen on github 👏 I really appreciate it |
Beta Was this translation helpful? Give feedback.
A top level async task is blocking as there is no way the sleep can execute while continuing to execute the code outside the event loop.
You should run your entire test inside an event, e.g.
If you are using Sus you can use
sus-fixtures-async
and write it like this:The reactor context also adds a 60s …