diff --git a/pages/SyntaxCase/index.uvue b/pages/SyntaxCase/index.uvue
index e3322dbee6764b3658ff5af35ac07a9108cf85e6..8d16dba3931955677ebc26df98b09e4e1dfe91e8 100644
--- a/pages/SyntaxCase/index.uvue
+++ b/pages/SyntaxCase/index.uvue
@@ -53,7 +53,10 @@
测试callback:{{ format(testUtsClassInstanceResult['callback']) }}
测试setter:{{ format(testUtsClassSetterResult) }}
-
+
+
+
+
@@ -73,6 +76,11 @@
request,
SetterTest,
} from "../../uni_modules/uts-syntaxcase";
+ // #endif
+ // #ifdef APP-IOS
+ import {
+ testPromiseStaticMethod
+ } from "@/uni_modules/uts-syntaxcase"
// #endif
let test:Test|null = null
let id = 0
@@ -441,7 +449,12 @@
} catch (e) {
console.error("testUtsClassSetter", e);
}
- },
+ },
+ // #ifdef APP-IOS
+ testPromiseStaticMethod() {
+ testPromiseStaticMethod()
+ }
+ // #endif
}
}
\ No newline at end of file
diff --git a/uni_modules/uts-syntaxcase/utssdk/index.uts b/uni_modules/uts-syntaxcase/utssdk/index.uts
index ab501a9bf159424123fa421ed86507d45a26874d..b9bc6bf0ce8209866c9d9705f915b7b8953e2d67 100644
--- a/uni_modules/uts-syntaxcase/utssdk/index.uts
+++ b/uni_modules/uts-syntaxcase/utssdk/index.uts
@@ -1,6 +1,9 @@
import { RequestTask, SyncOptions, AsyncOptions, SyntaxResult, SyncResult, TestOptions } from "./interface.uts";
import { log } from "./utils.uts";
+// #ifdef APP-IOS
+import { UTSPromiseAggregateError, UTSPromiseFulfilledResult, UTSPromiseRejectedResult} from "DCloudUTSFoundation";
+// #endif
/**
* 导出一个属性
@@ -121,6 +124,104 @@ export class Test {
}
}
+// #ifdef APP-IOS
+// #ifdef UNI-APP-X
+
+export function testPromiseStaticMethod() {
+ let p0 = new Promise((resolve, reject) => {
+ let success = true
+ setTimeout(() => {
+ if (success) {
+ const res : SyntaxResult = {
+ name: "pomise 0",
+ }
+ resolve(res);
+ } else{
+ reject(new Error("this is promise 0 reject reasion"))
+ }
+
+ }, 1000);
+ });
+
+ let p1 = new Promise((resolve, reject) => {
+ let success = true
+ setTimeout(() => {
+ if (success) {
+ resolve(null);
+ } else{
+ reject(new Error("this is promise 1 reject reasion"))
+ }
+
+ }, 2000);
+ });
+
+ let p2 = new Promise((resolve, reject) => {
+ let success = false
+ setTimeout(() => {
+ if (success) {
+ resolve(null);
+ } else{
+ // reject(new Error("this is promise 2 reject reasion"))
+ reject(null)
+ }
+
+ }, 2500);
+ });
+
+ // test for any
+ let pt = Promise.any([p0, p1, p2]);
+ pt.then( (res) => {
+ console.log("promise.any test success", res)
+ })
+ .catch( (error: any | null) => {
+ if (error instanceof UTSPromiseAggregateError) {
+ let err = error as UTSPromiseAggregateError
+ console.log(err.name, err.message, err.errors);
+ }else {
+ console.log(error);
+ }
+ })
+
+ // test for allSettled
+ Promise.allSettled([p0, p1, p2])
+ .then((res) => {
+ res.forEach((item, index) => {
+ if (item instanceof UTSPromiseFulfilledResult) {
+ let item0 = item as UTSPromiseFulfilledResult
+ console.log(item0.value, "UTSPromiseFulfilledResult value")
+ } else if (item instanceof UTSPromiseRejectedResult) {
+ let item0 = item as UTSPromiseRejectedResult
+ console.log(item0.reason, "UTSPromiseRejectedResult reason")
+ }
+ })
+ })
+ .catch((error: any | null) => {
+ console.log(error, "rejected test for promise.allSettled")
+ })
+
+ // test for all
+ Promise.all([p0, p1, p2])
+ .then((res)=> {
+ console.log(res, res.count)
+ })
+ .catch( (error: any | null) => {
+ console.log(error, "rejected test for promise.all")
+ })
+
+ // test for race
+ Promise.race([p0, p1, p2])
+ .then((res) => {
+ console.log(res, "resolved test for promise.race");
+ })
+ .catch((error: any | null) => {
+ console.log(error, "catch test for promise.race")
+ })
+}
+
+
+// #endif
+// #endif
+
export class SetterTest {
private _nickName: string = '';