Giter Site home page Giter Site logo

go-tools's Introduction

github.com/srcio/go

本仓库中封装了一些 go 语言常用的工具函数,可以在日常开发测试中使用。

下面是一些包的使用示例。

conc

  • 并发运行多个函数,会开启相应数量的 goroutine
conc.Run(func() {
    fmt.Println("Hello")
}, func() {
    fmt.Println("World")
})
  • 并发运行多个函数,并且等待所有函数完成
conc.Wait(func() {
    time.Sleep(1 * time.Second)
    fmt.Println("Hello")
}, func() {
    time.Sleep(4 * time.Second)
    fmt.Println("World")
})
  • 并发运行多个函数,并且捕获 panic
if p := conc.WaitAndRecover(func() {
fmt.Println("Hello")
panic("panic when print hello")
}, func() {
    fmt.Println("World")
    time.Sleep(1 * time.Second)
    panic("panic when print world")
}); p != nil {
    fmt.Printf("p.PanicInfo(): %v\n", p.PanicInfo())
    fmt.Printf("p.PanicVal(): %v\n", p.PanicVal())
}

go-tools's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.