资源加载中... loading...

setData

The setData() function is used to store variables in the thread context.

setData(key, value)

The key parameter is used to specify the key name of the stored key-value pair.

key true string The value parameter is used to specify the key value of the stored key-value pair.

value true Any type supported by the system, such as string, number, bool, object, array, null value, etc.

function main() {
    var t1 = threading.Thread(function() {
        threading.currentThread().setData("data", 100)
    })
    Sleep(1000)
    Log(`t1.getData("data"):`, t1.getData("data"))
    t1.join()
}

Set the key-value pair in the concurrent thread and read the key-value pair in the main thread.

The data is valid when the thread has not executed the join() function (waiting for exit success) and has not executed the terminate() function (terminating the thread forcibly). The value of the parameter value must be a serializable variable.

{@fun/Threads/Thread/peekMessage peekMessage}, {@fun/Threads/Thread/postMessage postMessage}, {@fun/Threads/Thread/join join}, {@fun/Threads/Thread/terminate terminate}, {@fun/Threads/Thread/getData getData}, {@fun/Threads/Thread/id id}, {@fun/Threads/Thread/name name}, {@fun/Threads/Thread/eventLoop eventLoop}

getData id