• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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
16/*
17 * @tc.name:promiseUseLazyValue
18 * @tc.desc:test promiseUseLazyValue
19 * @tc.type: FUNC
20 * @tc.require: issueIBBVLX
21 */
22import  lazy { LazyObjectForPromiseResolve } from "./lazyObjectForPromiseResolve"
23import  lazy { LazyObjectForPromiseReject } from "./lazyObjectForPromiseReject"
24import  lazy { LazyLogOutOfPromise } from "./lazyLogOutOfPromise"
25import  lazy { LazyLogForPromiseResolveExecutor } from "./lazyLogForPromiseResolveExecutor"
26import  lazy { LazyLogForPromiseRejectExecutor } from "./lazyLogForPromiseRejectExecutor"
27import  lazy { LazyLogForPromiseThen } from "./lazyLogForPromiseThen"
28import  lazy { LazyLogForPromiseCatch } from "./lazyLogForPromiseCatch"
29import  lazy { LazyLogForPromiseResolveFinally, LazyLogForPromiseRejectFinally } from "./lazyLogForPromiseFinally"
30import  lazy { lazyGenerator } from "./lazyGenerator"
31
32function promiseFuncResolved() {
33  return new Promise((resolve) => {
34    LazyLogForPromiseResolveExecutor.log("promiseFuncResolved executor");
35    resolve(new LazyObjectForPromiseResolve());
36  })
37}
38
39function promiseFuncRejected() {
40  return new Promise((resolve, reject) => {
41    LazyLogForPromiseRejectExecutor.log("promiseFuncRejected executor");
42    reject(new LazyObjectForPromiseReject());
43  })
44}
45
46function promiseUseLazyValue() {
47  const iterator = lazyGenerator();
48  promiseFuncResolved().then((lazyObj) => {
49    LazyLogForPromiseThen.log("promiseFuncResolved then " + iterator.next().value);
50    lazyObj.print();
51  }).finally(() => {
52    LazyLogForPromiseResolveFinally.log("promiseFuncResolved finally " + iterator.next().value)
53  })
54  promiseFuncRejected().catch((lazyObj) => {
55    LazyLogForPromiseCatch.log("promiseFuncRejected catch " + iterator.next().value);
56    lazyObj.print();
57  }).finally(() => {
58    LazyLogForPromiseRejectFinally.log("promiseFuncRejected finally " + iterator.next().value)
59  })
60  LazyLogOutOfPromise.log("testPromise end " + iterator.next().value);
61}
62
63promiseUseLazyValue()