• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  Generator functions are not supported
2
3Rule ``arkts-no-generators``
4
5**Severity: error**
6
7Currently, ArkTS does not support generator functions.
8Use the ``async`` / ``await`` mechanism for multitasking.
9
10
11## TypeScript
12
13
14```
15
16    function* counter(start: number, end: number) {
17        for (let i = start; i <= end; i++) {
18            yield i
19        }
20    }
21
22    for (let num of counter(1, 5)) {
23        console.log(num)
24    }
25
26```
27
28## ArkTS
29
30
31```
32
33    async function complexNumberProcessing(n : number) : Promise<number> {
34        // Some complex logic for processing the number here
35        return n
36    }
37
38    async function foo() {
39        for (let i = 1; i <= 5; i++) {
40            console.log(await complexNumberProcessing(i))
41        }
42    }
43
44    foo()
45
46```
47
48
49