Skip to content

Future and nil values #9

@mrbrdo

Description

@mrbrdo

There is a "problem" when a Future refers to a nil result (or false). The Future will seem like it is a NilClass object since Future is a BasicObject and will proxy almost everything to NilClass. However Future is truthy and not falsey like NilClass. This can be a huge pain to debug and figure out.

Maybe I can recommend some possible solutions. Please note I don't know this library very well.

  1. Define #class and #inspect and possibly a few other methods on Future, or at least inspect if you/people rely on class being the underlying class. Personally I would avoid doing it this way with BasicObject though as it is too much magic and very confusing.
  2. If I understand correctly, the future will be evaluated here: https://github.com/godfat/rest-core/blob/master/lib/rest-core/client.rb#L170 In this case it might be a good idea to return the actual object from this method instead of the future, so as to not leak out these "weird" objects. If the future has been resolved anyway there is no point in keeping the Future object anyway, you just want the result. Of course since instance_variable_get is also proxied you will need some kind of accessor method for that.

If possible it would be better to use SimpleDelegator from standard library to avoid this problem.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions