clarify how bidirectional communication should work
维护者通常 5 天内回复
还没有人认领这个 Issue。
- #247 来自 @ting-hong-shieh —— 已关闭,未合并
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- typescript
调研方向
从本 issue 中通过 newWebSocketRpcSession、RpcTarget、callback 函数和 timer 示例展示的双向通信行为开始。查看链接的示例 repository,以了解所演示的流程,然后通过可运行的示例记录通知式 callback 以及 async/timer 的易错点。完成的标准是,新贡献者能够理解如何使用双向通信,以及应该预期什么样的时序行为。
由索引模型根据 Issue 内容生成。
描述
Heya, neat library. Almost what I was asking for just a day ago 😆
I'm having a hard time understanding how to achieve bidirectional communication. It's almost worded like you can just push data back to the client, but I think that's not the right kind of thinking. So I dug deeper I ended up using the functionality that allows you to pass functions by reference- it seems like this is kind of what's intended?
Where it gets really confusing when you add things like timers into the equation. Without marking the method as async and awaiting a promise directly, it doesn't behave as you'd expect (from a "nieve" point of view, that is.)
I have an example repository you can use to explore this in more depth
Example client:
using wsApi = newWebSocketRpcSession<MyWs>("ws://localhost:8000");
const d = (sm: string) => console.log("got something: " + sm)
const wsResult = await wsApi.test(d);
console.log(wsResult);
Example websocket "client":
class WsServer extends RpcTarget {
async test(fn: (data: string) => void) {
fn("testing");
setTimeout(1000, () => {
fn("hello from timeout");
});
return true;
}
}
It'll call the first function, then return true. That makes a lot of sense! I would expect this to be a "gotcha" here and not a bug of the protocol (how would you know timers are involved?)
Now replace the setTimeout with an import from node:timers/promises:
class WsServer extends RpcTarget {
async test(fn: (data: string) => void) {
fn("testing");
const msg = await setTimeout(1000, "da");
fn(msg);
return true;
}
}
We'll get what we want:
got something: testing
got something: da
true
The ask here is if we can get some examples of bidirectional communication and the "gotchas" those comes with. I can see how functions can be used to achieve the "notification" style API for a client and this is something I'm looking to explore :)
- 主要语言
- TypeScript
- 星标
- 4k
- 派生
- 150
- 平均合并
- 3 天 12 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
cloudflare/capnweb 的其他 Issue
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
cloudflare/capnweb#269 · 2 条评论 ·
维护者通常 5 天内回复
-
难度 3/5 1-2 天 新手友好度 48/100
cloudflare/capnweb#260 ·
维护者通常 5 天内回复
-
onRpcBroken should return a Disposable so registrations can be undone可能重新可做 关联的 PR 已关闭且未合并。 未关闭enhancement
难度 4/5 3-5 天 新手友好度 35/100
cloudflare/capnweb#234 · 1 条评论 ·
维护者通常 5 天内回复
-
support `Map` serialization type可能已有人在做 @srikrsna 于 85 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
cloudflare/capnweb#230 ·
维护者通常 5 天内回复
-
难度 3/5 1-2 天 新手友好度 68/100
cloudflare/capnweb#228 ·
维护者通常 5 天内回复
查看 cloudflare/capnweb 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
components-web-app/docs#307 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
localstack/localstack-mcp-server#112 ·
维护者通常 1 天内回复
-
area:frontend kind:bug priority:p1 ready
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
bug ready-for-agent
难度 2/5 1-3 小时 新手友好度 73/100
PhyberApex/kuroshiro#1687 ·
维护者通常 1 天内回复
-
Performance (Web Vitals) collector: LCP/FCP from background tabs are not discarded, inflating p75未关闭
难度 2/5 1-3 小时 新手友好度 74/100
umami-software/umami#4720 ·
维护者通常 3 天内回复