package
Version:
v0.0.0-...-41c389d
Opens a new window with list of versions in this module.
Published: Apr 16, 2021
License: Apache-2.0
Opens a new window with license information.
Imports: 8
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
Documentation
¶
Close 触发 closing 信号, 通知相关的 goroutine 做好退出工作.
func Closing() <-chan struct{}
Closing 返回一个信号 chan, 当 Close 被调用后这个 chan 会收到通知.
Defer 会在 Wait 函数结束之前执行, 并且符合 FILO 的规则串行执行.
Defer 可以用于在程序退出之前做资源释放, 比如关闭数据库.
Go 开启一个新的 goroutine 用以执行 fn 函数, 第一个参数 ctx context.Context 会传递给 fn 的第一个参数 ctx context.Context.
当 Close 函数被调用或者收到系统的退出信号, fn 函数的 closing 会收到信号, fn 根据这个信号可以做一些逻辑.
Go 函数和语言级别的 go 关键字不同点在于 Wait 会等待 fn 执行结束.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.