Skip to content

Async task is appears to be blocking #364

Answered by ioquatix
stan-stately asked this question in Q&A
Discussion options

You must be logged in to vote

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 sus-fixtures-async and write it like this:

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 …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ioquatix
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #363 on November 29, 2024 01:20.