Skip to content

optimize: use context.WithCancelCause and context.AfterFunc to simplify streaming lifecycle control#1925

Open
DMwangnima wants to merge 1 commit intocloudwego:mainfrom
DMwangnima:optimize/streaming_go_1.21
Open

optimize: use context.WithCancelCause and context.AfterFunc to simplify streaming lifecycle control#1925
DMwangnima wants to merge 1 commit intocloudwego:mainfrom
DMwangnima:optimize/streaming_go_1.21

Conversation

@DMwangnima
Copy link
Contributor

What type of PR is this?

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

optimize: 使用 context.WithCancelCause 和 context.AfterFunc 来简化流式的生命周期管理

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:
zh(optional):

  1. Kitex 最低要求 go 版本升级至 1.21
  2. cancel 功能优化:使用 context.AfterFunc 替代 5s 一次的周期性轮训,cancel 感知和触发更快
  3. 使用 context.WithCancelCause 替代原有的 contextWithCancelCause。
    考虑到 streaming 提供的 ctx.Err() 一直会返回协议内部的定制化错误,为了不造成 Breaking Change,contextWithCancelCause 依然保留,只是在 Err() 接口被调用时自动执行 context.Cause 获取真正的错误

(Optional) Which issue(s) this PR fixes:

(optional) The PR that updates user documentation:

@DMwangnima DMwangnima requested review from a team as code owners February 13, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments