关于小程序中setData加锁问题?

小程序 文章 2021-03-10 10:21 74 0 全屏看文

关于小程序中setData加锁问题?About the setData locking problem in the applet?

关于小程序中setData加锁问题?

在开发中发现,当同一个时间并发运行的程序会出现脏数据的问题。在setData中取数据会出现数据问题。

比如:

VAR A=0;

B=>A=A+1

C=>A=A+1

D=>A=A+1

B,C,D同时运行的时候。有可能A的值为1;

我想A=3怎么做呢?变量或者setData怎么枷锁呢。

In the development, it is found that when programs run concurrently at the same time, dirty data will appear. There will be data problems when fetching data in SetData. For example: var a = 0; b = > A = a + 1, C = > A = a + 1, d = > A = a + 1, B, C, d run at the same time. It's possible that the value of a is 1; I think how to do a = 3? How can variables or SetData be chained.

回答:

陈宇明:

把A做成全局的

dreamhunter:

Promise.all

Mr.Zhao:

顺序执行呗

-EOF-