From ababbad5f992b5e4321f20d9b2329053846d6f42 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 2 Jul 2025 05:33:16 +0000 Subject: [PATCH 1/2] Initial plan From 206db35e8c1b279e6ac73a270c3124dd66186e12 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 2 Jul 2025 05:38:27 +0000 Subject: [PATCH 2/2] Export StateObject.ctx field as Ctx and update all references Co-authored-by: chmill-zz <17792380+chmill-zz@users.noreply.github.com> --- fsets.go | 14 +++++++------- fsets_test.go | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fsets.go b/fsets.go index 9e6b03b..24ca549 100644 --- a/fsets.go +++ b/fsets.go @@ -200,8 +200,8 @@ type StateObject[T any] struct { // Data is any data related to this call. Data T - // ctx is the context for this call. If a context is not provided, it will default to context.Background(). - ctx context.Context + // Ctx is the context for this call. If a context is not provided, it will default to context.Background(). + Ctx context.Context // err is an error that can be set by any function in the call chain. If this is set, the call chain will stop. err error @@ -228,7 +228,7 @@ func (s *StateObject[T]) GetStop() bool { // SetCtx sets the context for the StateObject. This is not used by users but is provided for // the fsets compiler. func (s *StateObject[T]) SetCtx(ctx context.Context) { - s.ctx = ctx + s.Ctx = ctx } // SetErr sets an error on the StateObject. This will stop the call chain and return the error in Err(). @@ -256,7 +256,7 @@ func (c C[T]) exec(so StateObject[T]) (StateObject[T], error) { return c.F(so) } err := c.B.Retry( - so.ctx, + so.Ctx, func(context.Context, exponential.Record) error { var err error so, err = c.F(so) @@ -308,7 +308,7 @@ func (f *Fset[T]) Run(ctx context.Context, so StateObject[T]) StateObject[T] { if ctx == nil { ctx = context.Background() } - so.ctx = ctx + so.Ctx = ctx if f.compiled != nil { // If we have a compiled version, use that. @@ -349,7 +349,7 @@ type PromiseQueue[T any] chan<- promises.Promise[StateObject[T], StateObject[T]] // Send sends a promise to the PromiseQueue. This is a blocking call until the promise is sent or the context is done. // The context is attached to the StateObject in the promise, so it can be used for cancelation. func (pq PromiseQueue[T]) Send(ctx context.Context, p promises.Promise[StateObject[T], StateObject[T]]) error { - p.In.ctx = ctx // Ensure the context is set on the StateObject. + p.In.Ctx = ctx // Ensure the context is set on the StateObject. select { case <-ctx.Done(): return context.Cause(ctx) @@ -422,7 +422,7 @@ func (f *Fset[T]) parallel(ctx context.Context, n int, options ...ParallelOption ctxNoCancel, func(ctx context.Context) error { // Run the Fset with the provided StateObject. - result := f.Run(so.ctx, so) + result := f.Run(so.Ctx, so) promise.Set(ctxNoCancel, result, result.Err()) if po.out != nil { po.out <- promise diff --git a/fsets_test.go b/fsets_test.go index 22a8159..8d7920f 100644 --- a/fsets_test.go +++ b/fsets_test.go @@ -65,7 +65,7 @@ func TestExec(t *testing.T) { for _, test := range tests { so := StateObject[Data]{} - so.ctx = t.Context() + so.Ctx = t.Context() so, err := test.c.exec(so) switch { case test.wantErr && err == nil: