actor: add CompleteWith and AwaitFuture generic package-level helpers
What changed, and why it matters
This commit adds two small helper functions to an internal actor package and updates the Go module file to use the local copy of that package. There is no security-relevant change; it is purely a code cleanup and convenience addition for future development work.
No security action required. Review as normal code-quality change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces CompleteWith[T] and AwaitFuture[T] generic helpers in actor/future.go. CompleteWith is a thin wrapper around Promise.Complete(fn.Ok(val)). AwaitFuture is a thin wrapper around Future.Await(ctx).Unpack(). The go.mod change bumps the actor module version from v0.0.3 to v0.0.5 and moves/re-adds a local replace directive so the new helpers are available immediately. No existing behavior is modified, no new state or concurrency primitives are introduced, and no security boundary is changed.
Changed components
actor/future.gogo.modInspect captured patch +21 / −4
diff --git a/actor/future.go b/actor/future.go
index 8c21169..d9edef0 100644
--- a/actor/future.go
+++ b/actor/future.go
@@ -17,6 +17,22 @@ type promiseImpl[T any] struct {
fut *futureImpl[T]
}
+// CompleteWith completes a promise with the given value, wrapping it as a
+// successful result. This is a convenience wrapper over
+// promise.Complete(fn.Ok(val)). Safe to call multiple times; only the first
+// call takes effect.
+func CompleteWith[T any](p Promise[T], val T) {
+ p.Complete(fn.Ok(val))
+}
+
+// AwaitFuture blocks until the future resolves or the context is cancelled.
+// On success, it returns the resolved value and a nil error. If the context
+// is cancelled before the future resolves, it returns the zero value of T and
+// the context cancellation error.
+func AwaitFuture[T any](ctx context.Context, f Future[T]) (T, error) {
+ return f.Await(ctx).Unpack()
+}
+
// NewPromise creates a new Promise. The associated Future, which consumers can
// use to await the result, can be obtained via the Future() method. The Future
// is completed by calling the Complete() method on this Promise.
diff --git a/go.mod b/go.mod
index 3aae8ac..7b44ded 100644
--- a/go.mod
+++ b/go.mod
@@ -33,7 +33,7 @@ require (
github.com/lightninglabs/neutrino v0.16.2
github.com/lightninglabs/neutrino/cache v1.1.3
github.com/lightningnetwork/lightning-onion v1.3.0
- github.com/lightningnetwork/lnd/actor v0.0.3
+ github.com/lightningnetwork/lnd/actor v0.0.5
github.com/lightningnetwork/lnd/cert v1.2.2
github.com/lightningnetwork/lnd/clock v1.1.1
github.com/lightningnetwork/lnd/fn/v2 v2.0.9
@@ -204,15 +204,16 @@ require (
sigs.k8s.io/yaml v1.2.0 // indirect
)
-// TODO(gijs): remove once new actor package is released.
-replace github.com/lightningnetwork/lnd/actor => ./actor
-
// TODO(gijs): remove once new queue package is released.
replace github.com/lightningnetwork/lnd/queue => ./queue
// TODO(elle): remove once the gossip V2 sqldb changes have been made.
replace github.com/lightningnetwork/lnd/sqldb => ./sqldb
+// Use local actor module to pick up CompleteWith/AwaitFuture helpers added
+// as part of the discovery errChan -> Future[error] migration.
+replace github.com/lightningnetwork/lnd/actor => ./actor
+
// This replace is for https://github.com/advisories/GHSA-25xm-hr59-7c27
replace github.com/ulikunitz/xz => github.com/ulikunitz/xz v0.5.11
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.