Skip to content

jolatechno/go-timeout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-timeout

Library use to create timeout from any function

Usage

Example code :

package main

import (
  "time"
  "fmt"
  "errors"

  "github.com/jolatechno/go-timeout"
)

func testFunc() (interface{}, error) {
  time.Sleep(2 * time.Second)
  return "returned", nil
}

func testFuncError() (interface{}, error) {
  time.Sleep(2 * time.Second)
  return nil, errors.New("Error")
}

func main() {
  fmt.Println(timeout.MakeTimeout(testFunc, 3 * time.Second))
  fmt.Println(timeout.MakeTimeout(testFunc, 1 * time.Second))
  fmt.Println(timeout.MakeTimeout(testFuncError, 3 * time.Second))
  fmt.Println(timeout.MakeTimeout(testFuncError, 1 * time.Second))
}

Output :

returned <nil>
<nil> Timed-out
<nil> Error
<nil> Timed-out

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages