|
@@ -1,13 +1,14 @@
|
|
|
-package concurrent
|
|
|
|
|
|
|
+package concurrent_test
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
+ "github.com/modern-go/concurrent"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func ExampleUnboundedExecutor_Go() {
|
|
func ExampleUnboundedExecutor_Go() {
|
|
|
- executor := NewUnboundedExecutor()
|
|
|
|
|
|
|
+ executor := concurrent.NewUnboundedExecutor()
|
|
|
executor.Go(func(ctx context.Context) {
|
|
executor.Go(func(ctx context.Context) {
|
|
|
fmt.Println("abc")
|
|
fmt.Println("abc")
|
|
|
})
|
|
})
|
|
@@ -16,7 +17,7 @@ func ExampleUnboundedExecutor_Go() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func ExampleUnboundedExecutor_StopAndWaitForever() {
|
|
func ExampleUnboundedExecutor_StopAndWaitForever() {
|
|
|
- executor := NewUnboundedExecutor()
|
|
|
|
|
|
|
+ executor := concurrent.NewUnboundedExecutor()
|
|
|
executor.Go(func(ctx context.Context) {
|
|
executor.Go(func(ctx context.Context) {
|
|
|
everyMillisecond := time.NewTicker(time.Millisecond)
|
|
everyMillisecond := time.NewTicker(time.Millisecond)
|
|
|
for {
|
|
for {
|
|
@@ -36,3 +37,15 @@ func ExampleUnboundedExecutor_StopAndWaitForever() {
|
|
|
// goroutine exited
|
|
// goroutine exited
|
|
|
// exectuor stopped
|
|
// exectuor stopped
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func ExampleUnboundedExecutor_Go_panic() {
|
|
|
|
|
+ concurrent.HandlePanic = func(recovered interface{}, file string, line int) {
|
|
|
|
|
+ fmt.Println("panic logged")
|
|
|
|
|
+ }
|
|
|
|
|
+ executor := concurrent.NewUnboundedExecutor()
|
|
|
|
|
+ executor.Go(func(ctx context.Context) {
|
|
|
|
|
+ panic("!!!")
|
|
|
|
|
+ })
|
|
|
|
|
+ time.Sleep(time.Second)
|
|
|
|
|
+ // output: panic logged
|
|
|
|
|
+}
|