From 5f864c44f2aa41d2f6984d8e6c635e031a08893e Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Thu, 24 Jan 2019 19:18:44 -0500 Subject: [PATCH] mrun: make Thread's callback not take in a context, it doesn't really help anything --- mrun/mrun.go | 4 ++-- mrun/mrun_test.go | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mrun/mrun.go b/mrun/mrun.go index 2d2b84c..6f60e3b 100644 --- a/mrun/mrun.go +++ b/mrun/mrun.go @@ -40,7 +40,7 @@ type ctxKey int // be canceled as well. // // See Wait for accompanying functionality. -func Thread(ctx mctx.Context, fn func(mctx.Context) error) { +func Thread(ctx mctx.Context, fn func() error) { futErr := newFutureErr() mctx.GetSetMutableValue(ctx, false, ctxKey(0), func(i interface{}) interface{} { futErrs, ok := i.([]*futureErr) @@ -51,7 +51,7 @@ func Thread(ctx mctx.Context, fn func(mctx.Context) error) { }) go func() { - futErr.set(fn(ctx)) + futErr.set(fn()) }() } diff --git a/mrun/mrun_test.go b/mrun/mrun_test.go index 70981e3..372089b 100644 --- a/mrun/mrun_test.go +++ b/mrun/mrun_test.go @@ -29,7 +29,7 @@ func TestThreadWait(t *T) { t.Run("noBlock", func(t *T) { t.Run("noErr", func(t *T) { ctx := mctx.New() - Thread(ctx, func(mctx.Context) error { return nil }) + Thread(ctx, func() error { return nil }) if err := Wait(ctx, nil); err != nil { t.Fatal(err) } @@ -37,7 +37,7 @@ func TestThreadWait(t *T) { t.Run("err", func(t *T) { ctx := mctx.New() - Thread(ctx, func(mctx.Context) error { return testErr }) + Thread(ctx, func() error { return testErr }) if err := Wait(ctx, nil); err != testErr { t.Fatalf("should have got test error, got: %v", err) } @@ -47,7 +47,7 @@ func TestThreadWait(t *T) { t.Run("block", func(t *T) { t.Run("noErr", func(t *T) { ctx := mctx.New() - Thread(ctx, func(mctx.Context) error { + Thread(ctx, func() error { time.Sleep(1 * time.Second) return nil }) @@ -58,7 +58,7 @@ func TestThreadWait(t *T) { t.Run("err", func(t *T) { ctx := mctx.New() - Thread(ctx, func(mctx.Context) error { + Thread(ctx, func() error { time.Sleep(1 * time.Second) return testErr }) @@ -69,7 +69,7 @@ func TestThreadWait(t *T) { t.Run("canceled", func(t *T) { ctx := mctx.New() - Thread(ctx, func(mctx.Context) error { + Thread(ctx, func() error { time.Sleep(5 * time.Second) return testErr }) @@ -89,7 +89,7 @@ func TestThreadWait(t *T) { t.Run("noBlock", func(t *T) { t.Run("noErr", func(t *T) { ctx, childCtx := ctxWithChild() - Thread(childCtx, func(mctx.Context) error { return nil }) + Thread(childCtx, func() error { return nil }) if err := Wait(ctx, nil); err != nil { t.Fatal(err) } @@ -97,7 +97,7 @@ func TestThreadWait(t *T) { t.Run("err", func(t *T) { ctx, childCtx := ctxWithChild() - Thread(childCtx, func(mctx.Context) error { return testErr }) + Thread(childCtx, func() error { return testErr }) if err := Wait(ctx, nil); err != testErr { t.Fatalf("should have got test error, got: %v", err) } @@ -107,7 +107,7 @@ func TestThreadWait(t *T) { t.Run("block", func(t *T) { t.Run("noErr", func(t *T) { ctx, childCtx := ctxWithChild() - Thread(childCtx, func(mctx.Context) error { + Thread(childCtx, func() error { time.Sleep(1 * time.Second) return nil }) @@ -118,7 +118,7 @@ func TestThreadWait(t *T) { t.Run("err", func(t *T) { ctx, childCtx := ctxWithChild() - Thread(childCtx, func(mctx.Context) error { + Thread(childCtx, func() error { time.Sleep(1 * time.Second) return testErr }) @@ -129,7 +129,7 @@ func TestThreadWait(t *T) { t.Run("canceled", func(t *T) { ctx, childCtx := ctxWithChild() - Thread(childCtx, func(mctx.Context) error { + Thread(childCtx, func() error { time.Sleep(5 * time.Second) return testErr })