Class: JSI::Util::Private::MemoMap Private
- Inherits:
-
Object
- Object
- JSI::Util::Private::MemoMap
- Defined in:
- lib/jsi/util/private/memo_map.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Instance Method Summary collapse
-
#initialize(key_by: nil, &block) ⇒ MemoMap
constructor
private
A new instance of MemoMap.
- #key_for(inputs) ⇒ Object private
Constructor Details
#initialize(key_by: nil, &block) ⇒ MemoMap
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of MemoMap.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/jsi/util/private/memo_map.rb', line 6 def initialize(key_by: nil, &block) @key_by = key_by @block = block || raise(ArgumentError, "no block given") # each result has its own mutex to update its memoized value thread-safely @result_mutexes = {} # another mutex to thread-safely initialize each result mutex @result_mutexes_mutex = Mutex.new @results = {} end |
Instance Method Details
#key_for(inputs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 21 22 23 24 |
# File 'lib/jsi/util/private/memo_map.rb', line 18 def key_for(inputs) if @key_by @key_by.call(**inputs) else inputs end end |