Go 语言优雅退出库 shutdown

码农软件 · 软件分类 · 常用工具包 · 2019-08-13 18:57:44

软件介绍

Go 语言在 1.7 版本中增加了 Context 库,优雅退出的实现有了一个统一的实现方式。

Go 语言 1.8 版本中 HTTP 服务使用 Context 实现了优雅退出。

使用此库可以方便地实现优雅退出:

    // Generate a new context
    ctx := NewContext()

    // Run service with this context
    go func(ctx context.Context) {
        if err := ExitWaitGroupAdd(ctx, 1); err != nil {
            return
        }
        defer ExitWaitGroupDone(ctx)

        otherEvent := make(chan struct{})
    FOR_LOOP:
        for {
            select {
            case <-ctx.Done():
                break FOR_LOOP
            case <-otherEvent:
                // ...
            }
        }

        // Some close processes
    }(ctx)

    // Wait interrupt signal
    sig := make(chan os.Signal)
    signal.Notify(sig, os.Interrupt)
    <-sig
    if err := Shutdown(ctx, time.Second*5); err != nil {
        log.Println("Shutdown error:", err)
        return
    }

本文地址:https://codercto.com/soft/d/12296.html

信息检索

信息检索

David A.Grossman、Ophir Frieder / 张华平 / 人民邮电出版社 / 201008 / 49.00元

随着Google、百度等搜索引擎公司的崛起,信息检索已经成为令人振奋的热门研究领域。 本书从发展的角度描述了ad hoc信息检索,讨论了用来实现大规模数据检索的最新算法。详细介绍了推理网络和系统的效率,并且对每种方法都给出了详细可行的实例。此外,本书整合了非结构化和结构化数据的处理技术,是其他教材所不具备的。第2版新增加了IR语言模型和跨语言检索。还讨论了许多当前的热点话题,如XML、P2P......一起来看看 《信息检索》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换