setData
The setData() function is used to store variables in the thread environment.
setData(key, value)Examples
-
Set a key-value pair in a concurrent thread and read the key-value pair in the main thread.
javascriptfunction main() { var t1 = threading.Thread(function() { threading.currentThread().setData("data", 100) }) Sleep(1000) Log(`t1.getData("data"):`, t1.getData("data")) t1.join() } -
Supports passing functions as key values.
javascriptfunction main() { threading.mainThread().setData("func2", function(p) { Log("func2 p:", p) }) var t1 = threading.Thread(function() { threading.currentThread().setData("func1", function(p) { Log("func1 p:", p) }) var func2 = threading.mainThread().getData("func2") func2("test2") }) Sleep(1000) var func1 = t1.getData("func1") func1("test1") t1.join() }
Arguments
| Name | Type | Required | Description |
key | string | Yes | The |
value | string / number / bool / object / array / function / any (any type supported by the platform) | Yes | The |
See Also
Remarks
Data remains valid as long as the thread has not executed the join() function (waiting for successful exit) and has not executed the terminate() function (forcibly terminating the thread). The value parameter must be a serializable variable.