• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16print("create promise");
17let promise = new Promise((resolve,reject) => {
18    resolve("resolve promise")
19})
20promise.then(result => {
21    print(result);
22})
23promise.finally(() => {
24    print("execute promise.finally");
25})
26
27print("create promise1");
28let promise1 = new Promise((resolve,reject) => {
29    reject("reject promise1")
30})
31promise1.catch(error => {
32    print(error);
33})
34promise1.finally(() => {
35    print("execute promise1.finally");
36})
37
38print("create promise2");
39let promise2 = new Promise((resolve,reject) => {
40    resolve("resolve promise2")
41})
42
43print("create promise3");
44let promise3 = new Promise((resolve,reject) => {
45    resolve("resolve promise3")
46})
47promise2.then(result => {
48    print(result);
49    promise3.then(result => {
50        print(result);
51    })
52})
53
54async function test() {
55    print("test start");
56    await test1();
57    print("test end");
58}
59
60async function test1() {
61    print("test1 start");
62    await test2();
63    print("test1 end");
64}
65
66async function test2() {
67    print("test2 start");
68    await test3();
69    print("test2 end");
70}
71
72function test3() {
73    print("execute test3");
74}
75
76print("execute test");
77test();