Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
exchange.Go
EventLoop
ctx.subscribe
ctx.poll
ctx.order
ctx.cancel
ctx.submit
Subscription
threading
Thread
Thread.peekMessage
Thread.postMessage
Thread.join
Thread.terminate
Thread.getData
Thread.setData
Thread.id
Thread.name
Thread.eventLoop
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Server
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Stores 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.

    javascript
    function 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.

    javascript
    function 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

NameTypeRequiredDescription

key

string

Yes

Key name of the key-value pair to be stored.

value

string / number / bool / object / array / function / any

Yes

Key value of the key-value pair to be stored.

See Also

Remarks

The data is kept with the Thread object; after the thread has ended (join() or terminate()), it can still be read through a Thread object you still hold. The value parameter must be a serializable variable.