after

说明

创建并返回一个函数, 等待函数运行指定次数后执行处理器

源码

用法

after.test.ts
1
import { after } from "../../utility/function/after";
2
3
describe('after', () => {
4
test('after should fire the handler with no params after the special times of function call', () => {
5
function doingWorkAsync(
6
props: { type: string, sign: (...args: any[]) => void },
7
) {
8
setTimeout(() => {
9
props.sign();
10
}, 0);
11
}
12
13
const employees = ['jack', 'rose', 'riven'];
14
const fragment = after(employees.length, () => {
15
expect(true).toBeTruthy();
16
});
17
18
for (const employee of employees) {
19
doingWorkAsync({ type: employee, sign: fragment });
20
}
21
});
22
23
test('after should fire the handler with any params after special times of function call', () => {
24
function doingWorkAsyncWithParams(
25
props: { type: string, sign: (...args: any[]) => void },
26
) {
27
setTimeout(() => {
28
props.sign(props.type);
29
}, 0);
30
}
31
32
const employees = ['jack', 'rose', 'riven'];
33
const fragment = after(employees.length, (type) => {
34
expect(type).toBe('riven');
35
});
36
37
for (const employee of employees) {
38
doingWorkAsyncWithParams({ type: employee, sign: fragment });
39
}
40
});
41
})
Copied!
最近更新 1yr ago
复制链接