{"id":124570,"date":"2026-11-19T05:40:52","date_gmt":"2026-11-18T21:40:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/124570.html"},"modified":"2026-11-19T05:40:52","modified_gmt":"2026-11-18T21:40:52","slug":"ticker-%e5%81%9c%e4%ba%86%ef%bc%8cgo-%e5%ae%9a%e6%97%b6%e4%bb%bb%e5%8a%a1%e4%b8%ba%e4%bb%80%e4%b9%88%e8%bf%98%e6%b2%a1%e9%80%80%e5%87%ba%ef%bc%9f%e6%8a%8a%e5%81%9c%e6%ad%a2%e5%92%8c%e7%ad%89%e5%ae%8c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/124570.html","title":{"rendered":"Ticker \u505c\u4e86\uff0cGo \u5b9a\u65f6\u4efb\u52a1\u4e3a\u4ec0\u4e48\u8fd8\u6ca1\u9000\u51fa\uff1f\u628a\u505c\u6b62\u548c\u7b49\u5b8c\u5206\u5f00"},"content":{"rendered":"<p>\u4e00\u4e2a\u670d\u52a1\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u5237\u65b0\u7f13\u5b58\u3002\u51c6\u5907\u9000\u51fa\u65f6\u8c03\u7528\u4e86 ticker.Stop()&#xff0c;\u65e5\u5fd7\u91cc\u5374\u4ecd\u80fd\u770b\u5230\u5237\u65b0\u52a8\u4f5c&#xff1b;\u53e6\u4e00\u79cd\u5199\u6cd5\u751a\u81f3\u4e00\u76f4\u5361\u5728 for range ticker.C&#xff0c;\u8fdb\u7a0b\u8fdf\u8fdf\u4e0d\u7ed3\u675f\u3002<\/p>\n<p>\u8fd9\u91cc\u6709\u4e09\u4ef6\u4e0d\u540c\u7684\u4e8b&#xff1a;\u4e0d\u518d\u4ea7\u751f\u540e\u7eed tick&#xff0c;\u8ba9\u8c03\u5ea6\u5faa\u73af\u8fd4\u56de&#xff0c;\u4ee5\u53ca\u7b49\u5f85\u5df2\u7ecf\u5f00\u59cb\u7684\u4efb\u52a1\u7ed3\u675f\u3002Stop \u53ea\u8d1f\u8d23\u5176\u4e2d\u4e00\u90e8\u5206\u3002\u60f3\u628a\u5b9a\u65f6\u4efb\u52a1\u6536\u5e72\u51c0&#xff0c;\u9700\u8981\u628a\u8fd9\u4e09\u4e2a\u52a8\u4f5c\u5206\u522b\u5b89\u6392\u597d\u3002<\/p>\n<p>\u4e0b\u9762\u4ee5\u8fdb\u7a0b\u5185\u7684\u5468\u671f\u5237\u65b0\u4e3a\u4f8b\u3002\u4ee3\u7801\u4e0e API \u6309 Go 1.26.5 \u6838\u5bf9&#xff0c;\u4f7f\u7528\u540c\u6b65\u6267\u884c\u7684\u4e00\u6b21\u4efb\u52a1&#xff0c;\u4e0d\u8ba8\u8bba\u8de8\u673a\u5668\u8c03\u5ea6\u6216\u9519\u8fc7\u540e\u5fc5\u987b\u8865\u8dd1\u7684\u8d26\u52a1\u4f5c\u4e1a\u3002<\/p>\n<h3>\u5148\u786e\u5b9a\u201c\u4e00\u5206\u949f\u4e00\u6b21\u201d\u5230\u5e95\u662f\u4ec0\u4e48\u610f\u601d<\/h3>\n<p>\u9700\u6c42\u5199\u7740\u201c\u4e00\u5206\u949f\u5237\u65b0\u4e00\u6b21\u201d&#xff0c;\u81f3\u5c11\u6709\u4e24\u79cd\u89e3\u91ca\u3002<\/p>\n<p>\u4e00\u79cd\u662f\u6309\u5468\u671f\u6536\u5230\u89e6\u53d1\u4fe1\u53f7&#xff1a;\u4ee5\u5206\u949f\u4e3a\u8282\u594f&#xff0c;\u4efb\u52a1\u5feb\u65f6\u6309\u8282\u594f\u6267\u884c&#xff1b;\u4efb\u52a1\u6162\u4e86&#xff0c;\u4e0d\u8981\u6c42\u628a\u6bcf\u4e2a\u9519\u8fc7\u7684\u89e6\u53d1\u90fd\u8865\u56de\u6765\u3002\u53e6\u4e00\u79cd\u662f\u672c\u6b21\u5b8c\u6210\u540e&#xff0c;\u518d\u4f11\u606f\u4e00\u5206\u949f&#xff0c;\u7136\u540e\u5f00\u59cb\u4e0b\u4e00\u6b21\u3002\u7b2c\u4e8c\u79cd\u7684\u4e24\u6b21\u5f00\u59cb\u65f6\u95f4\u95f4\u9694&#xff0c;\u5305\u542b\u4efb\u52a1\u8017\u65f6\u548c\u4f11\u606f\u65f6\u95f4\u3002<\/p>\n<p>Ticker \u66f4\u9002\u5408\u524d\u4e00\u79cd\u3002Go \u7684 NewTicker \u6587\u6863\u8bf4\u660e&#xff0c;\u63a5\u6536\u65b9\u8fc7\u6162\u65f6\u4f1a\u8c03\u6574\u95f4\u9694\u6216\u4e22\u5f03 tick\u3002\u5b83\u4e0d\u662f\u4fdd\u5b58\u6bcf\u6b21\u6267\u884c\u4e49\u52a1\u7684\u961f\u5217\u3002\u4e00\u6b21\u5237\u65b0\u82b1\u4e86\u5f88\u4e45&#xff0c;\u4e0d\u80fd\u636e\u6b64\u63a8\u65ad\u6062\u590d\u540e\u4e00\u5b9a\u4f1a\u8865\u8dd1\u591a\u5c11\u6b21\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u201c\u505a\u5b8c\u518d\u7b49\u201d&#xff0c;\u53ef\u4ee5\u5728\u6bcf\u6b21\u5de5\u4f5c\u8fd4\u56de\u540e\u542f\u52a8\u5355\u6b21 Timer \u7b49\u5f85&#xff0c;\u5e76\u540c\u65f6\u76d1\u542c\u53d6\u6d88&#xff1b;\u5b9a\u65f6\u5668\u5230\u671f\u540e\u518d\u5f00\u59cb\u4e0b\u4e00\u6b21\u3002\u4e24\u79cd\u8282\u594f\u90fd\u80fd\u6709\u7528&#xff0c;\u4f46\u4e0d\u80fd\u628a Ticker \u5305\u88c5\u6210\u56fa\u5b9a\u4f11\u606f\u65f6\u957f&#xff0c;\u4e5f\u4e0d\u80fd\u628a\u5b83\u627f\u8bfa\u4e3a\u4e0d\u6f0f\u6267\u884c\u7684\u8c03\u5ea6\u5668\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261118214046-6afe1b5e04f74.png\" alt=\"\u5468\u671f\u89e6\u53d1\u4e0e\u5b8c\u6210\u540e\u7b49\u5f85\u7684\u4e24\u6761\u65f6\u95f4\u8f74\uff0c\u6162\u4efb\u52a1\u671f\u95f4\u7684 tick \u4e0d\u5f62\u6210\u6301\u4e45\u4efb\u52a1\u961f\u5217\" \/><\/p>\n<h3>Stop \u4e0d\u5173\u95ed channel&#xff0c;\u4e5f\u4e0d\u64a4\u56de\u5df2\u7ecf\u5f00\u59cb\u7684\u5de5\u4f5c<\/h3>\n<p>ticker.Stop() \u540e\u4e0d\u4f1a\u518d\u53d1\u9001 tick&#xff0c;\u4f46\u5b83\u4e0d\u4f1a\u5173\u95ed ticker.C\u3002\u6240\u4ee5\u7b49 channel \u5173\u95ed\u624d\u7ed3\u675f\u7684 for range \u6ca1\u6709\u9000\u51fa\u4f9d\u636e\u3002\u9000\u51fa\u4fe1\u53f7\u5e94\u6765\u81ea\u53e6\u4e00\u4e2a\u901a\u9053&#xff0c;\u4f8b\u5982 ctx.Done()\u3002<\/p>\n<p>\u5355\u6b21 Timer \u4e5f\u4e0d\u80fd\u9760 Stop \u8ba9\u63a5\u6536\u7aef\u6536\u5230 channel \u5173\u95ed\u3002\u7528 AfterFunc \u542f\u52a8\u7684\u56de\u8c03\u8fd8\u591a\u4e00\u4e2a\u8fb9\u754c&#xff1a;\u56de\u8c03\u5df2\u7ecf\u5f00\u59cb\u65f6&#xff0c;Stop \u4e0d\u4f1a\u7b49\u5b83\u7ed3\u675f\u3002Go \u7684 Timer.Stop \u6587\u6863\u660e\u786e\u8981\u6c42\u9700\u8981\u7b49\u5f85\u7684\u8c03\u7528\u65b9\u81ea\u884c\u534f\u8c03\u3002<\/p>\n<p>\u4e0d\u8981\u628a\u201c\u5b9a\u65f6\u5668\u88ab\u505c\u6389\u201d\u8bb0\u5f55\u4e3a\u201c\u4efb\u52a1\u5df2\u7ed3\u675f\u201d\u3002\u5047\u8bbe\u5237\u65b0\u51fd\u6570\u5df2\u7ecf\u8fdb\u5165\u6570\u636e\u5e93\u8bf7\u6c42&#xff0c;\u505c\u6b62 ticker \u5e76\u4e0d\u4f1a\u81ea\u52a8\u64a4\u9500\u6570\u636e\u5e93\u64cd\u4f5c&#xff1b;\u53d6\u6d88\u4fe1\u53f7\u8981\u4f20\u7ed9\u5b9e\u9645\u64cd\u4f5c&#xff0c;\u5916\u5c42\u8fd8\u8981\u7b49\u5237\u65b0\u51fd\u6570\u8fd4\u56de\u3002<\/p>\n<p>\u672c\u6587\u4e0d\u4f9d\u8d56\u8bfb\u53d6 len(ticker.C)\u3001\u4e3b\u52a8\u6392\u7a7a channel \u6216 Timer.Reset \u7684\u5386\u53f2\u884c\u4e3a\u3002Go 1.23 \u8d77\u5b9a\u65f6\u5668 channel \u7684\u884c\u4e3a\u6709\u8c03\u6574&#xff0c;\u7ef4\u62a4\u65e7\u7a0b\u5e8f\u65f6\u8fd8\u8981\u6838\u5bf9\u4e3b\u6a21\u5757\u7248\u672c\u4e0e\u517c\u5bb9\u8bbe\u7f6e&#xff0c;\u4e0d\u80fd\u628a\u7f51\u4e0a\u7684\u6392\u7a7a\u6a21\u677f\u76f4\u63a5\u6df7\u5165\u65b0\u7684\u9000\u51fa\u903b\u8f91\u3002<\/p>\n<h3>\u540c\u6b65\u6267\u884c&#xff0c;\u5148\u628a\u91cd\u53e0\u95ee\u9898\u6d88\u6389<\/h3>\n<p>\u5bf9\u4e8e\u4e00\u4efd\u7f13\u5b58&#xff0c;\u540c\u4e00\u65f6\u523b\u901a\u5e38\u53ea\u9700\u8981\u4e00\u4e2a\u5237\u65b0\u4efb\u52a1\u3002\u6700\u76f4\u63a5\u7684\u5b9e\u73b0\u662f&#xff1a;\u6536\u5230 tick \u540e&#xff0c;\u5728\u8c03\u5ea6 goroutine \u91cc\u8c03\u7528 job&#xff0c;\u7b49\u5b83\u8fd4\u56de\u518d\u8fdb\u5165\u4e0b\u4e00\u8f6e\u3002\u4e0d\u8981\u5728\u6bcf\u6b21 tick \u540e\u968f\u624b\u5199 go job(ctx)&#xff0c;\u5426\u5219\u4e00\u6b21\u4efb\u52a1\u53d8\u6162&#xff0c;\u5c31\u53ef\u80fd\u4e0d\u65ad\u53e0\u51fa\u65b0\u4efb\u52a1\u3002<\/p>\n<p>func runPeriodic(ctx context.Context, period time.Duration,<br \/>\n    job func(context.Context) error) error {<br \/>\n    if period &lt;&#061; 0 {<br \/>\n        return errors.New(&#034;period must be positive&#034;)<br \/>\n    }<br \/>\n    ticker :&#061; time.NewTicker(period)<br \/>\n    defer ticker.Stop()<br \/>\n    for {<br \/>\n        select {<br \/>\n        case &lt;-ctx.Done():<br \/>\n            return ctx.Err()<br \/>\n        case &lt;-ticker.C:<br \/>\n            if err :&#061; ctx.Err(); err !&#061; nil {<br \/>\n                return err<br \/>\n            }<br \/>\n            if err :&#061; job(ctx); err !&#061; nil {<br \/>\n                return err<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>ctx, cancel :&#061; context.WithCancel(context.Background())<br \/>\ndone :&#061; make(chan error, 1)<br \/>\ngo func() { done &lt;- runPeriodic(ctx, period, refresh) }()<br \/>\n\/\/ \u670d\u52a1\u6536\u5230\u9000\u51fa\u4fe1\u53f7\u540e&#xff1a;<br \/>\ncancel()<br \/>\nerr :&#061; &lt;-done \/\/ \u6b64\u65f6 runPeriodic \u53ca\u5176\u4e2d\u540c\u6b65\u8c03\u7528\u7684 refresh \u5df2\u8fd4\u56de<\/p>\n<p>period \u548c refresh \u662f\u8c03\u7528\u65b9\u63d0\u4f9b\u7684\u5468\u671f\u4e0e\u5237\u65b0\u51fd\u6570\u3002\u8fd9\u6bb5\u793a\u4f8b\u7b2c\u4e00\u6b21\u6267\u884c\u8981\u7b49\u9996\u4e2a tick&#xff1b;\u5982\u679c\u542f\u52a8\u65f6\u5c31\u8981\u5237\u65b0&#xff0c;\u5e94\u53e6\u5199\u6e05\u695a\u9996\u8f6e\u884c\u4e3a\u3002\u793a\u4f8b\u5728\u4e00\u6b21\u5237\u65b0\u62a5\u9519\u540e\u505c\u6b62&#xff0c;\u5e76\u628a\u9519\u8bef\u4ea4\u7ed9\u8c03\u7528\u65b9&#xff0c;\u4e0d\u4f1a\u6084\u6084\u5ffd\u7565\u9519\u8bef\u518d\u91cd\u8bd5\u3002<\/p>\n<p>select \u4e0d\u4fdd\u8bc1\u53d6\u6d88\u5206\u652f\u4f18\u5148\u3002\u5f53 tick \u4e0e\u53d6\u6d88\u540c\u65f6\u5c31\u7eea\u65f6&#xff0c;\u53ef\u80fd\u5148\u9009\u4e2d tick&#xff0c;\u6240\u4ee5\u6267\u884c\u524d\u53c8\u68c0\u67e5\u4e86\u4e00\u6b21 ctx.Err()\u3002\u8fd9\u80fd\u907f\u5f00\u5df2\u89c2\u5bdf\u5230\u7684\u53d6\u6d88&#xff0c;\u4f46\u4e0d\u80fd\u628a\u68c0\u67e5\u4e0e\u4efb\u52a1\u5f00\u59cb\u53d8\u6210\u539f\u5b50\u64cd\u4f5c\u3002\u53d6\u6d88\u4ecd\u53ef\u80fd\u7d27\u63a5\u7740\u53d1\u751f&#xff0c;refresh \u81ea\u8eab\u5fc5\u987b\u5728\u53ef\u4e2d\u65ad\u7684\u7b49\u5f85\u70b9\u4f7f\u7528\u4f20\u5165\u7684 context\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261118214047-6afe1b5f966f3.png\" alt=\"\u4e00\u4e2a\u8c03\u5ea6 goroutine \u540c\u6b65\u6267\u884c\u5237\u65b0\uff0c\u4efb\u52a1\u8fd4\u56de\u524d\u4e0d\u542f\u52a8\u4e0b\u4e00\u6b21\uff1b\u53d6\u6d88\u901a\u77e5\u548c\u5b8c\u6210\u56de\u6267\u5206\u5f00\" \/><\/p>\n<h3>\u9000\u51fa\u8981\u7b49\u5728\u9014\u4efb\u52a1&#xff0c;\u800c\u4e0d\u662f\u7b49\u4e00\u4e2a\u4efb\u610f\u65f6\u957f<\/h3>\n<p>cancel() \u662f\u901a\u77e5&#xff0c;&lt;-done \u662f\u6536\u5c3e\u786e\u8ba4\u3002done \u53ea\u6709\u8c03\u5ea6 goroutine \u5199\u4e00\u6b21&#xff0c;\u5e76\u6709\u4e00\u4e2a\u7f13\u51b2\u4f4d&#xff1b;\u8c03\u7528\u65b9\u6682\u65f6\u6ca1\u63a5\u6536\u65f6&#xff0c;\u8fd4\u56de\u7ed3\u679c\u4e5f\u4e0d\u4f1a\u628a\u5b83\u5361\u4f4f\u3002\u8fd9\u91cc\u4e0d\u9700\u8981\u5173\u95ed done \u6765\u901a\u77e5\u591a\u8f6e\u7ed3\u679c&#xff0c;\u56e0\u4e3a\u5b83\u53ea\u4ee3\u8868\u4e00\u6b21\u8c03\u5ea6\u751f\u547d\u5468\u671f\u7684\u7ed3\u675f\u3002<\/p>\n<p>\u8fd9\u4e2a\u4fdd\u8bc1\u6709\u524d\u63d0&#xff1a;refresh \u8fd4\u56de\u65f6&#xff0c;\u5b83\u8d1f\u8d23\u7684\u5de5\u4f5c\u4e5f\u5df2\u7ecf\u7ed3\u675f\u3002\u82e5\u5b83\u5185\u90e8\u542f\u52a8\u4e86\u540e\u53f0 goroutine \u540e\u7acb\u523b\u8fd4\u56de&#xff0c;\u5916\u5c42\u7b49\u5230\u7684\u53ea\u662f\u51fd\u6570\u8fd4\u56de&#xff0c;\u4e0d\u80fd\u4ee3\u8868\u5185\u90e8\u4efb\u52a1\u7ed3\u675f\u3002\u5b50\u4efb\u52a1\u5e94\u5728\u5237\u65b0\u51fd\u6570\u5185\u7b49\u5b8c&#xff0c;\u6216\u8005\u7531\u66f4\u660e\u786e\u7684\u751f\u547d\u5468\u671f\u7ba1\u7406\u8005\u8d1f\u8d23\u3002<\/p>\n<p>\u5982\u679c\u5237\u65b0\u5ffd\u7565 context&#xff0c;\u5361\u5728\u65e0\u8d85\u65f6\u7684\u5916\u90e8\u8c03\u7528\u91cc&#xff0c;\u5916\u5c42\u4e5f\u53ea\u80fd\u7ee7\u7eed\u7b49\u5f85\u3002\u53ef\u4ee5\u4e3a\u6574\u4e2a\u670d\u52a1\u8bbe\u7f6e\u9000\u51fa\u7b49\u5f85\u4e0a\u9650&#xff0c;\u4f46\u4e0a\u9650\u8017\u5c3d\u8868\u793a\u201c\u672a\u80fd\u786e\u8ba4\u6536\u5c3e\u201d&#xff0c;\u4e0d\u80fd\u6253\u5370\u6210\u201c\u5168\u90e8\u4efb\u52a1\u5df2\u7ed3\u675f\u201d\u3002\u6570\u636e\u5e93\u3001HTTP \u548c\u6587\u4ef6\u64cd\u4f5c\u7684\u4e2d\u65ad\u80fd\u529b\u4e0d\u540c&#xff0c;\u8981\u5206\u522b\u67e5\u5176 API\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u79cd\u5bb9\u6613\u5ffd\u7565\u7684\u987a\u5e8f\u95ee\u9898&#xff1a;\u4e0d\u8981\u4ece refresh \u91cc\u9762\u7b49\u5f85\u81ea\u5df1\u7684 done&#xff0c;\u56e0\u4e3a done \u8981\u7b49 refresh \u8fd4\u56de\u540e\u624d\u4f1a\u5199\u5165\u3002\u505c\u6b62\u8bf7\u6c42\u53ef\u4ee5\u7531\u4efb\u52a1\u53d1\u8d77&#xff0c;\u7b49\u5f85\u5b83\u7ed3\u675f\u5219\u5e94\u7531\u5916\u5c42\u534f\u8c03\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261118214049-6afe1b6155925.png\" alt=\"\u9000\u51fa\u5206\u4e3a\u53d1\u51fa\u53d6\u6d88\u3001\u5728\u9014\u4efb\u52a1\u6536\u5c3e\u3001\u8c03\u5ea6\u8fd4\u56de\u4e09\u4e2a\u65f6\u523b\uff1b\u7b49\u5f85\u8d85\u65f6\u4e0d\u80fd\u6807\u8bb0\u4efb\u52a1\u5df2\u7ed3\u675f\" \/><\/p>\n<h3>\u7528\u4e8b\u4ef6\u987a\u5e8f\u9a8c\u8bc1&#xff0c;\u4e0d\u7528\u65e5\u5fd7\u65f6\u95f4\u731c<\/h3>\n<p>\u5c0f\u578b\u9a8c\u8bc1\u53ef\u4ee5\u8ba9\u5237\u65b0\u51fd\u6570\u4e3b\u52a8\u62a5\u544a\u201c\u5df2\u5f00\u59cb\u201d&#xff0c;\u968f\u540e\u7b49\u5f85\u6d4b\u8bd5\u4ee3\u7801\u653e\u884c\u3002\u6d4b\u8bd5\u5148\u53d6\u6d88&#xff0c;\u518d\u786e\u8ba4\u5b8c\u6210\u901a\u77e5\u5c1a\u672a\u5230\u8fbe&#xff1b;\u653e\u884c\u5237\u65b0\u540e&#xff0c;\u624d\u5e94\u6536\u5230\u8c03\u5ea6\u7ed3\u679c\u3002\u8fd9\u6837\u68c0\u67e5\u7684\u662f\u7b49\u5f85\u5173\u7cfb&#xff0c;\u4e0d\u662f\u67d0\u53f0\u673a\u5668\u80fd\u5426\u5728\u51e0\u6beb\u79d2\u5185\u8c03\u5ea6\u6210\u529f\u3002<\/p>\n<p>\u53e6\u4e00\u4e2a\u68c0\u67e5\u662f\u8bb0\u5f55\u540c\u65f6\u6267\u884c\u7684\u5237\u65b0\u6570\u91cf\u3002\u672c\u6587\u7684\u672c\u5730\u9a8c\u8bc1\u4f7f\u7528\u771f\u5b9e ticker \u548c\u53ef\u63a7\u5237\u65b0\u51fd\u6570&#xff0c;\u786e\u8ba4\u540c\u6b65\u8def\u5f84\u6700\u5927\u5728\u9014\u6570\u91cf\u4e3a\u4e00&#xff0c;\u5e76\u8986\u76d6\u7b49\u5f85\u9996\u4e2a tick \u65f6\u53d6\u6d88\u3001\u4efb\u52a1\u62a5\u9519\u9000\u51fa&#xff0c;\u4ee5\u53ca\u505c\u6b62 timer\/ticker \u4e0d\u5173\u95ed channel\u3002\u5b83\u4eec\u662f\u6807\u51c6\u5e93\u884c\u4e3a\u548c\u63a7\u5236\u6d41\u7a0b\u68c0\u67e5&#xff0c;\u4e0d\u662f\u751f\u4ea7\u8c03\u5ea6\u7cbe\u5ea6\u6216\u6027\u80fd\u6d4b\u8bd5\u3002<\/p>\n<p>\u8bb0\u5f55\u8fd0\u884c\u72b6\u6001\u65f6&#xff0c;\u53ef\u4ee5\u628a\u4e00\u6b21\u5237\u65b0\u8d4b\u4e88\u72ec\u7acb\u7f16\u53f7&#xff0c;\u5206\u522b\u8bb0\u4e0b\u5f00\u59cb\u3001\u8fd4\u56de\u539f\u56e0\u548c\u8c03\u5ea6\u7ed3\u675f\u3002\u6536\u5230\u53d6\u6d88\u65f6\u8bb0\u5f55\u201c\u505c\u6b62\u8bf7\u6c42\u5df2\u53d1\u51fa\u201d&#xff0c;\u6536\u5230 done \u65f6\u518d\u8bb0\u5f55\u201c\u5b9a\u65f6\u5faa\u73af\u5df2\u9000\u51fa\u201d\u3002\u82e5\u6ca1\u6709\u5f00\u59cb\u8bb0\u5f55\u5374\u770b\u89c1\u8fd4\u56de\u8bb0\u5f55&#xff0c;\u6216\u5faa\u73af\u7ed3\u675f\u540e\u8fd8\u6709\u540c\u7f16\u53f7\u7684\u4e1a\u52a1\u5199\u5165&#xff0c;\u5c31\u5e94\u8ffd\u67e5\u4efb\u52a1\u662f\u5426\u628a\u5de5\u4f5c\u5077\u5077\u4ea4\u7ed9\u4e86\u672a\u7eb3\u7ba1\u7684 goroutine\u3002<\/p>\n<p>\u8fd8\u5e94\u5728\u9700\u6c42\u91cc\u8bf4\u6e05\u6162\u5237\u65b0\u540e\u7684\u884c\u4e3a\u3002\u540c\u6b65\u8c03\u7528\u4fdd\u8bc1\u4e0d\u91cd\u53e0&#xff0c;\u4f46\u5e76\u4e0d\u627f\u8bfa\u8fd4\u56de\u540e\u8fd8\u80fd\u4f11\u606f\u5b8c\u6574\u5468\u671f&#xff1b;\u5df2\u6709\u7684\u89e6\u53d1\u53ef\u80fd\u5f88\u5feb\u88ab\u63a5\u6536\u3002\u5982\u679c\u6570\u636e\u5e93\u9700\u8981\u660e\u786e\u7684\u5598\u606f\u65f6\u95f4&#xff0c;\u5e94\u9009\u62e9\u201c\u5b8c\u6210\u540e\u518d\u7b49\u5f85\u201d\u7684\u5355\u6b21 timer \u65b9\u6848&#xff0c;\u800c\u4e0d\u662f\u901a\u8fc7\u589e\u5927 ticker \u5468\u671f\u731c\u6d4b\u8fd9\u4e2a\u95f4\u9694\u3002<\/p>\n<p>\u5982\u679c\u4e1a\u52a1\u8981\u6c42\u6bcf\u4e2a\u5468\u671f\u90fd\u5fc5\u987b\u6709\u8bb0\u5f55\u3001\u5931\u8d25\u53ef\u8865\u8dd1\u3001\u8fdb\u7a0b\u91cd\u542f\u540e\u63a5\u7740\u6267\u884c&#xff0c;\u5c31\u9700\u8981\u4fdd\u5b58\u4efb\u52a1\u72b6\u6001\u4e0e\u6267\u884c\u7ed3\u679c\u3002\u8fdb\u7a0b\u5185 ticker \u65e0\u6cd5\u63d0\u4f9b\u8fd9\u79cd\u4fdd\u8bc1\u3002\u5bf9\u666e\u901a\u7f13\u5b58\u5237\u65b0&#xff0c;\u5148\u8bf4\u6e05\u5468\u671f\u8bed\u4e49&#xff0c;\u518d\u786e\u8ba4\u201c\u505c\u6b62\u89e6\u53d1\u201d\u548c\u201c\u7b49\u5230\u7ed3\u675f\u201d\u5404\u81ea\u6709\u8d1f\u8d23\u4eba&#xff0c;\u9000\u51fa\u903b\u8f91\u5c31\u5bb9\u6613\u68c0\u67e5\u5f97\u591a\u3002<\/p>\n<p>            <span id=\"quality-guide-article-end\" aria-hidden=\"true\" style=\"display:block;height:1px;margin-bottom:-1px\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u670d\u52a1\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u5237\u65b0\u7f13\u5b58\u3002\u51c6\u5907\u9000\u51fa\u65f6\u8c03\u7528\u4e86 ticker.Stop()&#xff0c;\u65e5\u5fd7\u91cc\u5374\u4ecd\u80fd\u770b\u5230\u5237\u65b0\u52a8\u4f5c&#xff1b;\u53e6\u4e00\u79cd\u5199\u6cd5\u751a\u81f3\u4e00\u76f4\u5361\u5728 for range ticker.C&#xff0c;\u8fdb\u7a0b\u8fdf\u8fdf\u4e0d\u7ed3\u675f\u3002<br \/>\n\u8fd9\u91cc\u6709\u4e09\u4ef6\u4e0d\u540c\u7684\u4e8b&#xff1a;\u4e0d\u518d\u4ea7\u751f\u540e\u7eed tick&#xff0c;\u8ba9\u8c03\u5ea6\u5faa\u73af\u8fd4\u56de&#xff0c;\u4ee5\u53ca\u7b49\u5f85\u5df2\u7ecf\u5f00\u59cb\u7684\u4efb\u52a1\u7ed3\u675f\u3002Stop \u53ea\u8d1f\u8d23\u5176\u4e2d\u4e00\u90e8\u5206\u3002\u60f3\u628a\u5b9a\u65f6\u4efb\u52a1\u6536\u5e72\u51c0&#xff0c;\u9700\u8981\u628a\u8fd9\u4e09\u4e2a\u52a8\u4f5c\u5206\u522b\u5b89\u6392\u597d\u3002<br \/>\n\u4e0b\u9762\u4ee5\u8fdb\u7a0b\u5185\u7684\u5468\u671f\u5237\u65b0\u4e3a\u4f8b\u3002\u4ee3<\/p>\n","protected":false},"author":2,"featured_media":124567,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,50,207,86],"topic":[],"class_list":["post-124570","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-python","tag-50","tag-207","tag-86"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ticker \u505c\u4e86\uff0cGo \u5b9a\u65f6\u4efb\u52a1\u4e3a\u4ec0\u4e48\u8fd8\u6ca1\u9000\u51fa\uff1f\u628a\u505c\u6b62\u548c\u7b49\u5b8c\u5206\u5f00 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/124570.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ticker \u505c\u4e86\uff0cGo \u5b9a\u65f6\u4efb\u52a1\u4e3a\u4ec0\u4e48\u8fd8\u6ca1\u9000\u51fa\uff1f\u628a\u505c\u6b62\u548c\u7b49\u5b8c\u5206\u5f00 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u4e2a\u670d\u52a1\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u5237\u65b0\u7f13\u5b58\u3002\u51c6\u5907\u9000\u51fa\u65f6\u8c03\u7528\u4e86 ticker.Stop()&#xff0c;\u65e5\u5fd7\u91cc\u5374\u4ecd\u80fd\u770b\u5230\u5237\u65b0\u52a8\u4f5c&#xff1b;\u53e6\u4e00\u79cd\u5199\u6cd5\u751a\u81f3\u4e00\u76f4\u5361\u5728 for range ticker.C&#xff0c;\u8fdb\u7a0b\u8fdf\u8fdf\u4e0d\u7ed3\u675f\u3002 \u8fd9\u91cc\u6709\u4e09\u4ef6\u4e0d\u540c\u7684\u4e8b&#xff1a;\u4e0d\u518d\u4ea7\u751f\u540e\u7eed tick&#xff0c;\u8ba9\u8c03\u5ea6\u5faa\u73af\u8fd4\u56de&#xff0c;\u4ee5\u53ca\u7b49\u5f85\u5df2\u7ecf\u5f00\u59cb\u7684\u4efb\u52a1\u7ed3\u675f\u3002Stop \u53ea\u8d1f\u8d23\u5176\u4e2d\u4e00\u90e8\u5206\u3002\u60f3\u628a\u5b9a\u65f6\u4efb\u52a1\u6536\u5e72\u51c0&#xff0c;\u9700\u8981\u628a\u8fd9\u4e09\u4e2a\u52a8\u4f5c\u5206\u522b\u5b89\u6392\u597d\u3002 \u4e0b\u9762\u4ee5\u8fdb\u7a0b\u5185\u7684\u5468\u671f\u5237\u65b0\u4e3a\u4f8b\u3002\u4ee3\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/124570.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-18T21:40:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261118214046-6afe1b5e04f74.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/124570.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/124570.html\",\"name\":\"Ticker \u505c\u4e86\uff0cGo \u5b9a\u65f6\u4efb\u52a1\u4e3a\u4ec0\u4e48\u8fd8\u6ca1\u9000\u51fa\uff1f\u628a\u505c\u6b62\u548c\u7b49\u5b8c\u5206\u5f00 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-11-18T21:40:52+00:00\",\"dateModified\":\"2026-11-18T21:40:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/124570.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/124570.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/124570.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ticker \u505c\u4e86\uff0cGo \u5b9a\u65f6\u4efb\u52a1\u4e3a\u4ec0\u4e48\u8fd8\u6ca1\u9000\u51fa\uff1f\u628a\u505c\u6b62\u548c\u7b49\u5b8c\u5206\u5f00\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ticker \u505c\u4e86\uff0cGo \u5b9a\u65f6\u4efb\u52a1\u4e3a\u4ec0\u4e48\u8fd8\u6ca1\u9000\u51fa\uff1f\u628a\u505c\u6b62\u548c\u7b49\u5b8c\u5206\u5f00 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/124570.html","og_locale":"zh_CN","og_type":"article","og_title":"Ticker \u505c\u4e86\uff0cGo \u5b9a\u65f6\u4efb\u52a1\u4e3a\u4ec0\u4e48\u8fd8\u6ca1\u9000\u51fa\uff1f\u628a\u505c\u6b62\u548c\u7b49\u5b8c\u5206\u5f00 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u4e2a\u670d\u52a1\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u5237\u65b0\u7f13\u5b58\u3002\u51c6\u5907\u9000\u51fa\u65f6\u8c03\u7528\u4e86 ticker.Stop()&#xff0c;\u65e5\u5fd7\u91cc\u5374\u4ecd\u80fd\u770b\u5230\u5237\u65b0\u52a8\u4f5c&#xff1b;\u53e6\u4e00\u79cd\u5199\u6cd5\u751a\u81f3\u4e00\u76f4\u5361\u5728 for range ticker.C&#xff0c;\u8fdb\u7a0b\u8fdf\u8fdf\u4e0d\u7ed3\u675f\u3002 \u8fd9\u91cc\u6709\u4e09\u4ef6\u4e0d\u540c\u7684\u4e8b&#xff1a;\u4e0d\u518d\u4ea7\u751f\u540e\u7eed tick&#xff0c;\u8ba9\u8c03\u5ea6\u5faa\u73af\u8fd4\u56de&#xff0c;\u4ee5\u53ca\u7b49\u5f85\u5df2\u7ecf\u5f00\u59cb\u7684\u4efb\u52a1\u7ed3\u675f\u3002Stop \u53ea\u8d1f\u8d23\u5176\u4e2d\u4e00\u90e8\u5206\u3002\u60f3\u628a\u5b9a\u65f6\u4efb\u52a1\u6536\u5e72\u51c0&#xff0c;\u9700\u8981\u628a\u8fd9\u4e09\u4e2a\u52a8\u4f5c\u5206\u522b\u5b89\u6392\u597d\u3002 \u4e0b\u9762\u4ee5\u8fdb\u7a0b\u5185\u7684\u5468\u671f\u5237\u65b0\u4e3a\u4f8b\u3002\u4ee3","og_url":"https:\/\/www.wsisp.com\/helps\/124570.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-11-18T21:40:52+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/11\/20261118214046-6afe1b5e04f74.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/124570.html","url":"https:\/\/www.wsisp.com\/helps\/124570.html","name":"Ticker \u505c\u4e86\uff0cGo \u5b9a\u65f6\u4efb\u52a1\u4e3a\u4ec0\u4e48\u8fd8\u6ca1\u9000\u51fa\uff1f\u628a\u505c\u6b62\u548c\u7b49\u5b8c\u5206\u5f00 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-11-18T21:40:52+00:00","dateModified":"2026-11-18T21:40:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/124570.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/124570.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/124570.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Ticker \u505c\u4e86\uff0cGo \u5b9a\u65f6\u4efb\u52a1\u4e3a\u4ec0\u4e48\u8fd8\u6ca1\u9000\u51fa\uff1f\u628a\u505c\u6b62\u548c\u7b49\u5b8c\u5206\u5f00"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/124570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=124570"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/124570\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/124567"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=124570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=124570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=124570"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=124570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}