socketry / async

An awesome asynchronous event-driven reactor for Ruby.
MIT License
2.12k stars 86 forks source link

fiber-annotation package cause issue with LSpace #320

Closed junyuanz1 closed 3 months ago

junyuanz1 commented 3 months ago

So I am trying to use async library with lspace.

one thing I noticed is that for async 2.6.0 and version up. I can't do something like this anymore

LSpace.with_context(team_id: 1) do
  Async do |task|
    expect(LSpace.team_id).must_equal 1

    task.async { expect(LSpace.team_id).must_equal 1 }
  end
end

basically LSpace also has a Fiber class https://github.com/ConradIrwin/lspace/blob/master/lib/lspace/fiber.rb it is having trouble to import the correct one. I am wondering if there is any workaround for this.

Thank you!

ioquatix commented 3 months ago

This code is problematic: https://github.com/ConradIrwin/lspace/blob/83e0382fb89a5d1c98e219078a5ff4cce6cd37d1/lib/lspace/core_ext.rb#L46-L65

Basically, it should be rewritten to use a module to wrap the method, rather than renaming it.

junyuanz1 commented 3 months ago

That makes sense. So I guess we have to use 2.5.1 unless we can modify the lspace package?

ioquatix commented 3 months ago

FYI, you can probably replace LSpace with Fiber[] storage.

e.g.

LSpace.with(:user_id => 5) do
  Fiber.new { LSpace[:user_id] == 5 }.resume
end

# becomes

Fiber[:user_id] = 5
Fiber.new { Fiber[:user_id] == 5 }.resume
junyuanz1 commented 3 months ago

Thank you so much! Fiber storage works!