timeout

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 3 Imported by: 1

README

Timeout - Give timeout power for function

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/timeout

Getting Started

func TestTimeout(t *testing.T) {
	fn := func() error {
		time.Sleep(100 * time.Millisecond)
		fmt.Println("fn done")
		return nil
	}

	err := Timeout(fn, 50*time.Millisecond)
	if err == nil {
		t.Errorf("expected timeout error, got nil")
	}

	err = Timeout(fn, 300*time.Millisecond)
	if err != nil {
		t.Errorf("expected nil, got %v", err)
	}
}

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.0.3"

Version is the version of this package.

Functions

func Timeout

func Timeout(fn func() error, timeout time.Duration, message ...string) (err error)

Timeout call the function with timeout

Types

This section is empty.

Jump to

Keyboard shortcuts

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