Sample code:
mss = game:GetService("MemoryStoreService")
test = mss:GetSortedMap("Test")
s = os.clock()
timeout = 3
task.spawn(function()
print("spawn update", test:UpdateAsync("0", function(v) print("spawn received", v) return (v or 0) + 2 end, timeout))
print("spawn", os.clock() - s)
end)
print("main update", test:UpdateAsync("0", function(v) print("main received", v) return (v or 0) + 1 end, timeout))
print("main", os.clock() - s)
Some of the time the two UpdateAsync transform functions will run at the same time and produce this output:
spawn received nil
main received nil
spawn update 2
spawn 0.1831044999999
main update 1
main 0.1833445999946
I printed out the value of the key after both finished and indeed it was ‘1’ (expected value: ‘3’)
Expected behaviour: It should run UpdateAsync a second time for one of the transform functions even when the previous value was nil (OR this behaviour should be documented so developers can avoid bugs!)