Share data cross fiber the the traditional way?

I would strongly recommend against reopening Fiber to add an instance variable unless you have very specific reason to do so.

What’s the actual use case, though? What do you need that fiber local variable for?

In the example you’re just passing in a value which can be done in a couple of different ways much easier and less intrusively.

Just because you can do this in Ruby doesn’t mean you should do a similar thing in Crystal. Heck, it doesn’t even mean it was a good call to use it in Ruby in the first place.

Transforming Ruby code to Crystal with a focus on equivalence to the Ruby implementation will inevitably result in bad software design and potentially buggy behaviour. Ruby and Crystal are similar in many ways, but there are also a lot of significant differences (for example in concurrency mechanisms).

IMO it’s a wast of time if you’re just trying to find equivalents for Ruby and you’ll get a sub-par result.
Try to solve the problem in Crystal instead. Use the tools you have in Crystal. The Ruby implementation can serve as inspiration, of course.
Make it about the problem you want to solve, not about translating one solution for the problem found in Ruby.

3 Likes