diff --git a/actor/future.go b/actor/future.go index 8c211691f..d9edef015 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 3aae8ace1..7b44ded8b 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