socketry / async

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

Your gem does not load whole class. I had to do this instead. #355

Closed limjinsun closed 2 weeks ago

limjinsun commented 2 weeks ago

It's great gem. I was able to minimize time for long-running task. But your gem doesn't load class.. So I had to download and made some change.

Screenshot 2024-11-08 at 09 40 51

You can close this ticket. But please be aware.

ioquatix commented 2 weeks ago

Thanks for your report.

This is by design.

In the future we may use something like zeitwerk.

trevorturk commented 2 weeks ago

It could be worth considering a style like Rails where you have the option to do require rails/all.

ioquatix commented 2 weeks ago

I'm slightly against this style, because I've seen it become problematic. Basically, it creates situations where there are implicit dependencies via intermediate requires. You basically depend on something that you aren't explicitly requiring.

This can become a problem because people don't realise there are implicit dependencies. So, for a long time, require "rack" would work fine, but require "rack/thing" would usually break. We now test every file's tests separately to confirm that requiring a specific file would be okay, e.g. https://github.com/rack/rack/blob/fc541f3f443ed170b9b1daed4d16c6407a12573d/test/spec_builder.rb#L2-L12

Rails has a lot of issues like this. Want to use class ActiveX::Y::Z?, then:

require 'active_x/y/z`

ActiveX::Y::Z.new # probably fails due to missing stuff

In async, every component should be able to require itself, and expresses all dependencies.