From 569eeac5002d6f40775b65624a54787a412380ce Mon Sep 17 00:00:00 2001 From: Jimmy Tanagra Date: Fri, 25 Aug 2023 22:02:18 +1000 Subject: [PATCH 1/2] Fix timer reschedule example in USAGE.md Signed-off-by: Jimmy Tanagra --- USAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/USAGE.md b/USAGE.md index 17b9165a1e..45b5610728 100644 --- a/USAGE.md +++ b/USAGE.md @@ -850,7 +850,7 @@ It can be rescheduled to a different duration ```ruby after(3.minutes) do |timer| My_Light.on - my_timer.reschedule(1.minute) + timer.reschedule(1.minute) end ``` From e927ebd36e84b0b947f9c0de0c51cb2d81c7ae02 Mon Sep 17 00:00:00 2001 From: Jimmy Tanagra Date: Fri, 25 Aug 2023 22:03:13 +1000 Subject: [PATCH 2/2] Fix shared_cache examples Signed-off-by: Jimmy Tanagra --- USAGE.md | 14 +++++++------- lib/openhab/core/value_cache.rb | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/USAGE.md b/USAGE.md index 45b5610728..af0a8dab4d 100644 --- a/USAGE.md +++ b/USAGE.md @@ -922,22 +922,22 @@ Just be wary of Ruby-only data types (such as Symbols) that won't be accessible Get a previously set object with a default value: ```ruby -counter_object = shared_cache.compute_if_absent(:counter) { { "times" => 0 } } -logger.info("Count: #{counter_object["times"] += 1}")" +shared_cache.compute_if_absent(:counter) { 0 } # Initialize with 0 if it didn't exist +logger.info("Count: #{shared_cache[:counter] += 1}") ``` Get a previously set object, or assign it (this version is subject to race conditions with other scripts): ```ruby -counter_object = shared_cache[:counter] ||= { "times" => 0 } -logger.info("Count: #{counter_object["times"] += 1}")" +shared_cache[:counter] ||= 0 +logger.info("Count: #{shared_cache[:counter] += 1}") ``` -Get a previously set object with a default value, without assigning it (this version has an even longer amount of time between fetchig the value and assigning it): +Get a previously set object with a default value, without assigning it (this version has an even longer amount of time between fetching the value and assigning it): ```ruby -count = shared_count.fetch(:counter) { 0 } -shared_count[:counter] = count + 1 +count = shared_cache.fetch(:counter) { 0 } +shared_cache[:counter] = count + 1 ``` ### Time diff --git a/lib/openhab/core/value_cache.rb b/lib/openhab/core/value_cache.rb index e8fd1d63a3..2e26d79c43 100644 --- a/lib/openhab/core/value_cache.rb +++ b/lib/openhab/core/value_cache.rb @@ -28,7 +28,7 @@ module Core # For a private cache, simply use an instance variable. See # {file:docs/ruby-basics.md#variables Instance Variables}. # - # @note Because every script or UI rule gets it own JRuby engine instance, + # @note Because every script or UI rule gets its own JRuby engine instance, # you cannot rely on being able to access Ruby objects between them. Only # objects that implement a Java interface that's part of Java or openHAB # Core (such as Hash implements {java.util.Map}, or other basic