From 09fdc64ae50ce5b539a3af1fad5ac514046af6a5 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Thu, 1 Feb 2024 16:13:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0async=20=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=9A=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/SyntaxCase/index.vue | 43 +++++++++++++++++++-- uni_modules/uts-syntaxcase/utssdk/index.uts | 20 +++++++++- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/pages/SyntaxCase/index.vue b/pages/SyntaxCase/index.vue index 88f19b5..6951915 100644 --- a/pages/SyntaxCase/index.vue +++ b/pages/SyntaxCase/index.vue @@ -13,7 +13,11 @@ 测试return:{{ format(testUtsAsyncResult.return) }} 测试success:{{ format(testUtsAsyncResult.success) }} - 测试complete:{{ format(testUtsAsyncResult.complete) }} + 测试complete:{{ format(testUtsAsyncResult.complete) }} + + 测试return:{{ format(testUtsAsyncMulitParamResult.return) }} + 测试success:{{ format(testUtsAsyncMulitParamResult.success) }} + 测试complete:{{ format(testUtsAsyncMulitParamResult.complete) }} 测试callback:{{ format(testUtsClassConstructorResult.callback) }} @@ -55,7 +59,8 @@ MAX, testSync, testSyncWithCallback, - testAsync, + testAsync, + testAsyncParam3, Test, request, } from "../../uni_modules/uts-syntaxcase"; @@ -77,6 +82,12 @@ success: null, fail: null, complete: null, + }, + testUtsAsyncMulitParamResult: { + return: null, + success: null, + fail: null, + complete: null, }, testUtsClassConstructorResult: { callback: null @@ -124,7 +135,8 @@ testAll() { this.testUtsSync(); this.testUtsSyncWithCallback(); - this.testUtsAsync(); + this.testUtsAsync(); + this.testUtsAsyncMulitParam() this.testUtsClassConstructor(); this.testUtsClassStaticProp(); this.testUtsClassStaticSyncWithCallback(); @@ -195,6 +207,31 @@ this.testUtsAsyncResult.return = true; } } catch (e) {} + }, + async testUtsAsyncMulitParam() { + this.testUtsAsyncMulitParamResult.return = false; + this.testUtsAsyncMulitParamResult.success = false; + // testUtsAsyncResult.fail = false; + this.testUtsAsyncMulitParamResult.complete = false; + try { + const res = await testAsyncParam3(100,"hello",{ + type: "success", + success: (res) => { + console.log("testUtsAsyncMulitParam.success.callback", res); + this.testUtsAsyncMulitParamResult.success = true; + }, + fail: (res) => { + console.log("testUtsAsyncMulitParam.fail.callback", res); + }, + complete: (res) => { + console.log("testUtsAsyncMulitParam.complete.callback", res); + this.testUtsAsyncMulitParamResult.complete = true; + }, + }); + if (res.name === "testUtsAsyncMulitParam") { + this.testUtsAsyncMulitParamResult.return = true; + } + } catch (e) {} }, testUtsClassConstructor() { this.testUtsClassConstructorResult.callback = false diff --git a/uni_modules/uts-syntaxcase/utssdk/index.uts b/uni_modules/uts-syntaxcase/utssdk/index.uts index ed2e57d..9858ac3 100644 --- a/uni_modules/uts-syntaxcase/utssdk/index.uts +++ b/uni_modules/uts-syntaxcase/utssdk/index.uts @@ -95,7 +95,25 @@ export async function testAsync(opts : AsyncOptions) : Promise { } return await testAwaitPromise(res); // return { name: "testAsync" }; -} +} + + +export async function testAsyncParam3(id:number,name:string,opts : AsyncOptions) : Promise { + console.log("id",id,"name",name) + if (opts.type == "success") { + opts.success("success"); + } else { + opts.fail("fail"); + } + opts.complete("complete"); + + const res : SyntaxResult = { + name: "testUtsAsyncMulitParam" + } + return await testAwaitPromise(res); + // return { name: "testAsync" }; +} + export type TestOptions = { name : string; -- GitLab