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