goroutine 与生命周期

启动能被停止的后台任务:goroutine 配对 WaitGroup,用 context 作为唯一停止通道,退出前确认无残留。

Go进阶约 30 分钟
开始学习
学习目标
  • 编写可被 context 停止的 ticker 后台任务
  • 用 WaitGroup 的 Add/Done/Wait 配对确认任务结束
  • 用 goroutine 数量旁证服务退出时没有泄漏
知识点
goroutinesync.WaitGrouptime.Ticker生命周期

内容版本 1.0.0,核验于 2026-10-26

Command Palette

Search for a command to run...