Dictionary object, used for data sharing.
The get()
function is used to get the key value recorded in the dictionary object.
The get()
function returns the value of the key specified by the key
parameter.
string, number, bool, object, array, null value and other types supported by the system
get(key)
The key
parameter is used to specify the key name corresponding to the key to be obtained.
key true string
function main() {
var event = threading.Event()
var dict = threading.Dict()
dict.set("data", 100)
var t1 = threading.Thread(function(dict, event) {
Log(`thread1, dict.get("data"):`, dict.get("data"))
event.set()
event.clear()
event.wait()
Log(`after main change data, thread1 dict.get("data"):`, dict.get("data"))
dict.set("data", 0)
}, dict, event)
event.wait()
dict.set("data", 99)
event.set()
event.clear()
t1.join()
Log(`main thread, dict.get("data"):`, dict.get("data"))
}
Use event objects to notify threads to read and modify data.
{@fun/Threads/ThreadDict/set set}
The set()
function is used to set a key-value pair.
set(key, value)
The parameter key
is used to set the key name to be modified.
key
true
string
The parameter value
is used to set the key value to be modified.
value true string, number, bool, object, array, function, null value and other types supported by the system
function main() {
var dict1 = threading.Dict()
dict1.set("func1", function(p) {
Log("func1 p:", p)
})
threading.Thread(function(dict1) {
var func1 = dict1.get("func1")
func1("test")
}, dict1).join()
}
It supports key-value passing into functions.
{@fun/Threads/ThreadDict/get get}
ThreadCondition Web3