Skip to content

Commit

Permalink
Ack flag on state object has priorty (in setState/setStateDelayed)
Browse files Browse the repository at this point in the history
  • Loading branch information
klein0r committed Jun 5, 2024
1 parent fff65c4 commit 05da77b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Executes Javascript, Typescript Scripts.
<!--
### **WORK IN PROGRESS**
-->
### **WORK IN PROGRESS**

* (klein0r) Ack flag on state object has priorty (in setState/setStateDelayed)

### 8.4.3 (2024-06-04)

* (klein0r) Added response time to httpGet and httpPost result
Expand Down
14 changes: 9 additions & 5 deletions lib/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ function sandBox(script, name, verbose, debug, context) {
if (isObject(state) && state.val !== undefined) {
// we assume that we were given a state object if
// state is an object that contains a `val` property
state.ack = isAck;
if (!Object.prototype.hasOwnProperty.call(state, 'ack')) {
state.ack = isAck;
}
} else {
// otherwise, assume that the given state is the value to be set
state = { val: state, ack: isAck };
Expand Down Expand Up @@ -432,8 +434,10 @@ function sandBox(script, name, verbose, debug, context) {

// modify state here, to make it available in callback
if (!isObject(state) || state.val === undefined) {
state = {val: state};
state.ack = isAck || false;
state = {
val: state,
ack: isAck || false,
};
}

// we only need this when state cache is used
Expand Down Expand Up @@ -1023,7 +1027,7 @@ function sandBox(script, name, verbose, debug, context) {
callback = clearRunning;
clearRunning = delay;
delay = isAck;
isAck = false;
isAck = undefined;
}
if (typeof delay !== 'number') {
callback = clearRunning;
Expand Down Expand Up @@ -2018,7 +2022,7 @@ function sandBox(script, name, verbose, debug, context) {
callback = clearRunning;
clearRunning = delay;
delay = isAck;
isAck = false;
isAck = undefined;
}
if (typeof delay !== 'number') {
callback = clearRunning;
Expand Down
6 changes: 4 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,16 @@ function convertBackStringifiedValues(id, state) {

function prepareStateObject(id, state, isAck) {
if (state === null) {
state = {val: null};
state = { val: null };
}

if (isAck === true || isAck === false || isAck === 'true' || isAck === 'false') {
if (isObject(state) && state.val !== undefined) {
// we assume that we were given a state object if
// state is an object that contains a `val` property
state.ack = isAck;
if (!Object.prototype.hasOwnProperty.call(state, 'ack')) {
state.ack = isAck;
}
} else {
// otherwise assume that the given state is the value to be set
state = {val: state, ack: isAck};
Expand Down

0 comments on commit 05da77b

Please sign in to comment.