Documentation ¶
Overview ¶
Package aop is Aspect Oriented Programming.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parallel ¶
func Parallel(funcs ...interface{})
Parallel can make works in parallel, and wait for all complete.
Example:
aop.Parallel(func(complete chan bool) { t.Log(1) complete <- true }, func(complete chan bool) { t.Log(2) complete <- true }, func(complete chan bool) { t.Log(3) complete <- true }, func(complete chan bool) { t.Log(4) complete <- true }, func(complete chan bool) { t.Log(5) complete <- true })
func Recover ¶
func Recover(work func(), onErr func(interface{}))
Recover just like try...catch to other languages
func Retry ¶
func Retry(work func(), times int)
Retry will call work while work cause panic in times
func Sequence ¶
func Sequence(funcs ...interface{})
Sequence can make parallel work in sequence, and 2nd func can have input from 1st func's return value, and so on.
Example:
aop.Sequence(func(next chan bool, exit chan bool) int { fmt.Println(1, "=>", 1) next <- true return 1 }, func(next chan bool, exit chan bool, a int) int { fmt.Println(2, "=>", a) next <- true return a + 1 }, func(next chan bool, exit chan bool, a int) int { fmt.Println(3, "=>", a) next <- true return a + 1 }, func(next chan bool, exit chan bool, a int) int { fmt.Println(4, "=>", a) exit <- true return a + 1 }, func(next chan bool, exit chan bool, a int) { fmt.Println(5, "=>", a) next <- true })
Types ¶
type Aspect ¶
type Aspect interface { Recover(err func(interface{})) Aspect Retry(times int) Aspect Repeat(times int) Aspect Delay(d time.Duration) Aspect Do(work func()) }
Aspect can do calls like chain
NewAspect(). Retry(3). Delay(10 * time.Second). Repeat(5). Do(func() { fmt.Println("Test") })
Means print Test line 5 times, after 10 seconds, if panic happen retry 3 times.
Click to show internal directories.
Click to hide internal directories.