Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code Review] js 回调 golang 的方法 #119

Open
PIGfaces opened this issue Aug 3, 2022 · 0 comments
Open

[Code Review] js 回调 golang 的方法 #119

PIGfaces opened this issue Aug 3, 2022 · 0 comments

Comments

@PIGfaces
Copy link
Contributor

PIGfaces commented Aug 3, 2022

问题描述

在阅读源码感叹大佬的强大时,修炼尚浅的我无法明白注入页面的 addLink 使用异步函数方法重写的原因。大佬可否解答一下。
为何最后要再通过 DeliverResult 方法来触发,这里有点绕

window["addLink"] = async(...args) => {
const me = window["addLink"];
let callbacks = me['callbacks'];
if (!callbacks) {
callbacks = new Map();
me['callbacks'] = callbacks;
}
const seq = (me['lastSeq'] || 0) + 1;
me['lastSeq'] = seq;
const promise = new Promise(fulfill => callbacks.set(seq, fulfill));
binding(JSON.stringify({name: "addLink", seq, args}));
return promise;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant