app

package
v0.0.0-...-41c389d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close()

Close 触发 closing 信号, 通知相关的 goroutine 做好退出工作.

func Closing

func Closing() <-chan struct{}

Closing 返回一个信号 chan, 当 Close 被调用后这个 chan 会收到通知.

func Defer

func Defer(fn func())

Defer 会在 Wait 函数结束之前执行, 并且符合 FILO 的规则串行执行.

Defer 可以用于在程序退出之前做资源释放, 比如关闭数据库.

func Go

func Go(ctx context.Context, fn func(ctx context.Context, closing <-chan struct{}))

Go 开启一个新的 goroutine 用以执行 fn 函数, 第一个参数 ctx context.Context 会传递给 fn 的第一个参数 ctx context.Context.

当 Close 函数被调用或者收到系统的退出信号, fn 函数的 closing 会收到信号, fn 根据这个信号可以做一些逻辑.

Go 函数和语言级别的 go 关键字不同点在于 Wait 会等待 fn 执行结束.

func Wait

func Wait()

Wait 等待所有的 Go 任务退出然后才退出.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL