From cdcb2a26b6289645dfefac5ef7995765278685a2 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Wed, 11 Dec 2024 16:42:11 +0100 Subject: [PATCH] [jsscripting] Upgrade openhab-js to 5.8.1 Changelog: https://github.com/openhab/openhab-js/blob/main/CHANGELOG.md#581. Signed-off-by: Florian Hotze --- .../org.openhab.automation.jsscripting/README.md | 13 ++++++++++--- bundles/org.openhab.automation.jsscripting/pom.xml | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.automation.jsscripting/README.md b/bundles/org.openhab.automation.jsscripting/README.md index 0063b1c4aac5c..14b3300a9d4b9 100644 --- a/bundles/org.openhab.automation.jsscripting/README.md +++ b/bundles/org.openhab.automation.jsscripting/README.md @@ -809,13 +809,20 @@ See [openhab-js : actions.NotificationBuilder](https://openhab.github.io/openhab The cache namespace provides both a private and a shared cache that can be used to set and retrieve data that will be persisted between subsequent runs of the same or between scripts. The private cache can only be accessed by the same script and is cleared when the script is unloaded. -You can use it to store both primitives and objects, e.g. store timers or counters between subsequent runs of that script. +You can use it to store primitives and objects, e.g. store timers or counters between subsequent runs of that script. When a script is unloaded and its cache is cleared, all timers (see [`createTimer`](#createtimer)) stored in its private cache are automatically cancelled. The shared cache is shared across all rules and scripts, it can therefore be accessed from any automation language. The access to every key is tracked and the key is removed when all scripts that ever accessed that key are unloaded. If that key stored a timer, the timer will be cancelled. -You can use it to store **only primitives**, as storing objects is not thread-safe and can cause script execution failures. +You can use it to store primitives and **Java** objects, e.g. store timers or counters between multiple scripts. + +Due to a multi-threading limitation in GraalJS (the JavaScript engine used by JavaScript Scripting), it is not recommended to store JavaScript objects in the shared cache. +Multi-threaded access to JavaScript objects will lead to script execution failure! +You can work-around that limitation by either serialising and deserialising JS objects or by switching to their Java counterparts. + +Timers as created by [`createTimer`](#createtimer) can be stored in the shared cache. +The ids of timers and intervals as created by `setTimeout` and `setInterval` cannot be shared across scripts as these ids are local to the script where they were created. See [openhab-js : cache](https://openhab.github.io/openhab-js/cache.html) for full API documentation. @@ -1240,7 +1247,7 @@ Operations and conditions can also optionally take functions: ```javascript rules.when().item("F1_light").changed().then(event => { - console.log(event); + console.log(event); }).build("Test Rule", "My Test Rule"); ``` diff --git a/bundles/org.openhab.automation.jsscripting/pom.xml b/bundles/org.openhab.automation.jsscripting/pom.xml index 2c6324d3ac2a2..7484a086d99f4 100644 --- a/bundles/org.openhab.automation.jsscripting/pom.xml +++ b/bundles/org.openhab.automation.jsscripting/pom.xml @@ -25,7 +25,7 @@ 22.0.0.2 ${project.version} - openhab@5.8.0 + openhab@5.8.1