1 Star 0 Fork 13

胖子的梦/ani_cookbook

forked from Xingwa/ani_cookbook 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
promise_test.sts 1.37 KB
一键复制 编辑 原始数据 按行查看 历史
Xingwa 提交于 2025-02-15 23:47 +08:00 . 增加want参数
export class Want{
public value:int;
public constructor(v:int) {
this.value = v;
}
}
export class Ability{
static { loadLibrary("promise_test") }
private native execute(want:Want):int;
private native gettid():int;
startAbility(want:Want):Promise<int>{
console.log("Start Ability in thread" + this.gettid() + ".");
let p = new Promise<int>((resolve: (v: int) => void, reject: (error: Object) => void) => {
//let p1 = launch this.execute();
let p1 = taskpool.execute(this.execute,want);
p1.then((e :NullishType)=>{
console.log("P1 then in thread" + this.gettid() + ".");
console.log("P1 then e = " + e + ".");
let r : Int = e as Int;
resolve(r.intValue());
});
console.log("Promise execute in thread" + this.gettid() + ".");
});
return p;
}
}
function main(){
let ab = new Ability;
let want = new Want(42);
let p = ab.startAbility(want);
console.log("Start Invoked");
p.then<void, void>((value: int): void => {
if (value != 7) {
console.log("Test failed. The promise shoule be fulfilled by 7 but got " + value + ".");
return;
}
console.log("Test passed.");
}, (err: Object): void => {
console.log("Test failed. The promise shouldn`t be rejected.");
});
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pangzidemeng/ani_cookbook.git
git@gitee.com:pangzidemeng/ani_cookbook.git
pangzidemeng
ani_cookbook
ani_cookbook
master

搜索帮助