-
Notifications
You must be signed in to change notification settings - Fork 2
/
MergingStep.wpy
109 lines (97 loc) · 3.05 KB
/
MergingStep.wpy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<template>
<view>
<button @tap="onAction">请求<text class="sub">({{groupType==='control' ? actionHintControl : actionHintExp}})</text></button>
<view class="logs">
<view class="record" wx:for="{{logs}}" wx:for-item="record" wx:key="{{index}}">{{record}}</view>
<view class="clear" @tap="onClear" wx:if="{{logs.length>0}}">clear</view>
</view>
</view>
</template>
<script>
import wepy from 'wepy';
import {noConcurrent,mergingStep,singleAisle,makeMutex} from 'fancy-mini/lib/decorator/noConcurrent';
import {semanticTimestamp} from '@/lib/utils';
import {delay} from 'fancy-mini/lib/operationKit';
export default class extends wepy.component {
props = {
groupType: {
type: String,
}
}
data = {
actionHintControl: '连续点击,重复执行',
actionHintExp: '公共步骤将合并执行',
clkCount: 0,
logs: [],
}
computed = {}
methods = {
async onAction(){
let funcName = ['funcA', 'funcB', 'funcC'][this.clkCount%3];
this[funcName]();
++this.clkCount;
},
onClear(){
this.logs = [];
this.$apply();
}
}
printLog(...msgs){
this.logs.push(semanticTimestamp()+' '+msgs.join(''));
this.$apply();
}
async funcA(){
this.printLog('[funcA] enter');
let loginRes = await (this.groupType==='control' ? this.loginControl() : this.loginExp());
this.printLog('[funcA] loginRes: ',loginRes);
await delay(600);
this.printLog('[funcA] exit');
}
async funcB(){
this.printLog('[funcB] enter');
let loginRes = await (this.groupType==='control' ? this.loginControl() : this.loginExp());
this.printLog('[funcB] loginRes: ', loginRes);
await delay(600);
this.printLog('[funcB] exit');
}
async funcC(){
this.printLog('[funcC] enter');
let loginRes = await (this.groupType==='control' ? this.loginControl() : this.loginExp());
this.printLog('[funcC] loginRes: ', loginRes);
await delay(600);
this.printLog('[funcC] exit');
}
async loginControl(){ //无免并发处理,连续多次调用会多次执行,造成性能浪费和可能的并发干扰
this.printLog('[login] enter');
await delay(1000);
this.printLog('[login] finished');
return 'success';
}
@mergingStep //免并发处理:合并
async loginExp(){ //有免并发处理,连续多次调用只会执行一次,后续调用将会等待并使用该次执行结果,而不会重复执行,节约性能并避免并发执行相互干扰
this.printLog('[login] enter');
await delay(1000);
this.printLog('[login] finished');
return 'success';
}
components = {
}
}
</script>
<style lang="less" rel="stylesheet/less">
</style>
<style lang="less" rel="stylesheet/less" scoped>
.sub {
font-size: 22rpx;
}
.logs {
.record, .clear {
font-size: 28rpx;
line-height: 42rpx;
color: #969696;
}
.clear {
text-decoration: underline;
}
}
</style>