ocisly

package module
v0.0.0-...-7ccbb80 Latest Latest
Warning

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

Go to latest
Published: May 24, 2016 License: MIT Imports: 5 Imported by: 0

README

ocisly

package ocisly contains a goroutine Wait function that could be used in testing environment.

Name inspired by SpaceX drone ship Of Course I Still Love you.

GoDoc

A simple example

func f() {}

func main() {
	go f()
	ocisly.Wait("github.com/bom-d-van/pkg.f")
}

Explanations:

Wait waits until you named gorouine finish. Using DefaultTimeout (initialized 10 seconds)

If the Wait exits before your goroutine started, you could specify a large
IntervalBegin to avoid this problem.

How to figure out your function name. Basically it's {{ImportPath}}.{{FuncName}}.
		Case 1: function named "Func" from package (same or other) named "github.com/alice/pkg"
				ocisly.Wait("github.com/alice/pkg.Func")
		Case 2: method named "method" in type "*typ" from package (same or other) named "github.com/alice/pkg"
				ocisly.Wait("github.com/alice/pkg.(*typ).method")
		Case 3: first anonymous function called "foo" in function/method named "Func" in package (same or other)
				named "github.com/alice/pkg".
				ocisly.Wait("github.com/alice/pkg.Func.func1")
Running examples could be found in file ocisly_test.go.

Disclaimer: cases mentioned above isn't comprehensive, so if your function is
complicated to figure out by human brain, you could call
ocisly.PrintGoroutines() to help you figure out what name is your gorouinte using.

Suggestion: to improve Wait accuracy, you could turn your inline/anonymous function to a named function.

Documentation

Overview

package ocisly contains a goroutine Wait function that could be used in testing environment.

Name inspired by SpaceX drone ship Of Course I Still Love you (https://en.wikipedia.org/wiki/Autonomous_spaceport_drone_ship).

Index

Constants

This section is empty.

Variables

View Source
var DefaultTimeout = time.Second * 10
View Source
var IntervalBegin = time.Millisecond * 30

Functions

func PrintGoroutines

func PrintGoroutines()

PrintGoroutines prints out all the goroutine stack.

func PrintSuggestions

func PrintSuggestions()

PrintSuggestions prints function/method name suggestions that could be used in Wait function.

func Wait

func Wait(name string)

Wait waits until you named gorouine finish. Using DefaultTimeout (initialized 10 seconds)

If the Wait exits before your goroutine started, you could specify a large IntervalBegin to avoid this problem.

How to figure out your function name. Basically it's {{ImportPath}}.{{FuncName}}.

Case 1: function named "Func" from package (same or other) named "github.com/alice/pkg"
		ocisly.Wait("github.com/alice/pkg.Func")
Case 2: method named "method" in type "*typ" from package (same or other) named "github.com/alice/pkg"
		ocisly.Wait("github.com/alice/pkg.(*typ).method")
Case 3: first anonymous function called "foo" in function/method named "Func" in package (same or other)
		named "github.com/alice/pkg".
		ocisly.Wait("github.com/alice/pkg.Func.func1")

Running examples could be found in file ocisly_test.go.

Disclaimer: cases mentioned above isn't comprehensive, so if your function is complicated to figure out by human brain, you could call ocisly.PrintGoroutines() to help you figure out what name is your gorouinte using.

Suggestion: to improve Wait accuracy, you could turn your inline/anonymous function to a named function.

func WaitTimeout

func WaitTimeout(name string, timeout time.Duration)

WaitTimeout works same as Wait, but supports timeout specification.

Types

This section is empty.

Jump to

Keyboard shortcuts

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