Error in executeScript code: E353: csPostMessage: timeout 5000 ms

I have an asynchronous call to an API which takes a while to process and is cut off by the 5000ms timeout.
This function is invoked by executeScript.
Does anyone know how/where to alter that timeout to make it bigger?

The code:

async function callApi(keyword) {
  	const response = await fetch (api_url);
	const data = await response.json();
	return data;
}
return callApi(${keyword});
1 Like

Hello, this 5 second timeout value is currently hardcoded, but adding a custom variable for it is on our todo list for the next updates.

2 Likes

+1 The same struggle here.

I found this hardcode timeout in the plugin code. Making that a variable will be super handy! :pray:

When is this improvement planned?

Soon! :wink:

Here is a test macro (currently still fails):

{
  "Name": "timeout",
  "CreationDate": "2024-2-15",
  "Commands": [
    {
      "Command": "echo",
      "Target": "runtime=${!runtime}",
      "Value": "brown",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "20",
      "Value": "!timeout_wait",
      "Description": "New feature:  executeScript  will use this value (here: 20s), but at least have 5s"
    },
    {
      "Command": "executeScript",
      "Target": "var start = new Date().getTime();\nvar delay = 2000; \nwhile (new Date().getTime() < start + delay) {\n    \n}\nreturn 123; \n",
      "Value": "a",
      "Description": "This works! (2s delay)"
    },
    {
      "Command": "echo",
      "Target": "runtime=${!runtime}, a1=${a}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "executeScript",
      "Target": "var start = new Date().getTime();\nvar delay = 8000; \nwhile (new Date().getTime() < start + delay) {\n    \n}\nreturn 888; \n",
      "Value": "a",
      "Description": "This fails (8s delay)"
    },
    {
      "Command": "echo",
      "Target": "runtime=${!runtime}, a2=${a}",
      "Value": "blue",
      "Description": ""
    }
  ]
}

This issue is solved in V9.0.5 :slight_smile:

Now executeScript waits at least 5 seconds or the !timeout_wait value (if > 5).

Test macro:

{
  "Name": "api1",
  "CreationDate": "2024-2-19",
  "Commands": [
    {
      "Command": "echo",
      "Target": "runtime=${!runtime}",
      "Value": "brown",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "15",
      "Value": "!timeout_wait",
      "Description": "New feature:  executeScript  waits until !timeout_wait (here: 15s), but at least 5s."
    },
    {
      "Command": "executeScript",
      "Target": "var start = new Date().getTime();\nvar delay = 12000; \nwhile (new Date().getTime() < start + delay) {\n    \n}\nreturn 3; \n",
      "Value": "a",
      "Description": "This script takes 12 seconds to run"
    },
    {
      "Command": "echo",
      "Target": "runtime=${!runtime}, return value=${a}",
      "Value": "blue",
      "Description": ""
    }
  ]
}
2 Likes