Conversation
da-liii
reviewed
Feb 13, 2026
| (lambda (response) | ||
| (set! async-completed #t) | ||
| (set! async-response response))) | ||
| (http-wait-all 30) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[210_20] 异步 HTTP API
注:该 API 由于 S7 的线程不安全,只能暴露一个 poll 来推进进度。在 QT 中应当将 poll 放在循环中定时调用,或自定义事件通知开始更新。
任务相关的代码文件
src/goldfish.hppgoldfish/liii/http.scmtests/goldfish/liii/http-test.scmdemo/async_http_demo.scmdemo/async_vs_sync_demo.scm如何测试
2026/2/13 实现 libcpr 异步 HTTP 绑定
What
新增 C++ 层异步 HTTP 绑定:
f_http_async_get/glue_http_async_get:异步 GET 请求f_http_async_post/glue_http_async_post:异步 POST 请求f_http_async_head/glue_http_async_head:异步 HEAD 请求f_http_poll/glue_http_poll:非阻塞轮询完成的请求f_http_wait_all/glue_http_wait_all:阻塞等待所有请求完成新增 Scheme 层包装函数:
http-async-get:(http-async-get url callback [params] [headers] [proxy])http-async-post:(http-async-post url callback [params] [data] [headers] [proxy])http-async-head:(http-async-head url callback [params] [headers] [proxy])http-poll:检查并执行已完成的回调http-wait-all:(http-wait-all [timeout])等待所有请求完成新增 demo 文件:
demo/async_http_demo.scm:展示基本用法、并发请求、轮询机制demo/async_vs_sync_demo.scm:对比同步和异步请求的性能差异新增测试用例:
http-poll返回值测试Why
提供真正的异步 HTTP 请求能力,使多个 HTTP 请求可以并发执行而不阻塞主线程。这对于需要同时请求多个资源的场景(如批量 API 调用、并行数据获取)可以显著提升性能。
How
使用 libcpr 原生异步 API:通过
session.GetAsync()、session.PostAsync()、session.HeadAsync()启动异步请求,利用 libcpr 内部的全局线程池执行网络 I/O。Session 生命周期管理:使用
std::shared_ptr<cpr::Session>保持 Session 对象存活,直到异步操作完成,避免bad_weak_ptr错误。线程安全的回调机制:
http-poll或http-wait-all检查完成的请求并执行回调s7_gc_protect/s7_gc_unprotect_at保护 Scheme 回调不被 GC并发执行验证:3 个 delay/1 的请求总耗时约 2 秒(而非 6 秒),证明请求是并发执行的。