Skip to content

Commit

Permalink
Simplify enabling concurrent_write
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Brown committed Jul 9, 2024
1 parent b18d336 commit 5f6cf05
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
22 changes: 11 additions & 11 deletions lib/cached_resource/cached_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ def cached_resource(options={})
def setup_cached_resource!(options)
@cached_resource = CachedResource::Configuration.new(options)
# puts "OK WE ARE SET UP!"
if @cached_resource.concurrent_write
@cached_resource.require_concurrent_ruby
# begin
# send :require, 'concurrent/promise'
# rescue LoadError
# @cached_resource.logger.error(
# "`concurrent_write` option is enabled, but `concurrent-ruby` is not an installed dependency"
# )
# raise
# end
end
# if @cached_resource.concurrent_write
# @cached_resource.require_concurrent_ruby
# # begin
# # send :require, 'concurrent/promise'
# # rescue LoadError
# # @cached_resource.logger.error(
# # "`concurrent_write` option is enabled, but `concurrent-ruby` is not an installed dependency"
# # )
# # raise
# # end
# end
send :include, CachedResource::Caching
@cached_resource
end
Expand Down
6 changes: 4 additions & 2 deletions lib/cached_resource/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def initialize(options={})

# Set our concurrent_write. Can't override OpenStruct setters
# in a straightforward way.
@concurrent_write = data.delete :concurrent_write
# @concurrent_write = data.delete :concurrent_write
self.concurrent_write = data.delete :concurrent_write
super(data)
end

Expand All @@ -68,10 +69,11 @@ def off!
self.enabled = false
end

# Toggle writing to cache in a thread. Requires
# concurrent/promise if enabled.
def concurrent_write=(value)
require_concurrent_ruby if value
@concurrent_write = value
puts "WE REQUIRED ID!\n", value
end

# require concurrent/promise, throwing an exception if necessary
Expand Down

0 comments on commit 5f6cf05

Please sign in to comment.