feat: add launch_with_fn (#8694)

This commit is contained in:
Matthias Seitz
2024-06-10 12:49:23 +02:00
committed by GitHub
parent 40fc19f085
commit 53f4ecade4
2 changed files with 20 additions and 0 deletions

View File

@ -220,6 +220,14 @@ impl<T: FullNodeTypes, CB: NodeComponentsBuilder<T>> NodeBuilderWithComponents<T
launcher.launch_node(self).await
}
/// Launches the node with the given closure.
pub fn launch_with_fn<L, R>(self, launcher: L) -> R
where
L: FnOnce(Self) -> R,
{
launcher(self)
}
/// Check that the builder can be launched
///
/// This is useful when writing tests to ensure that the builder is configured correctly.

View File

@ -58,6 +58,18 @@ pub trait LaunchNode<Target> {
fn launch_node(self, target: Target) -> impl Future<Output = eyre::Result<Self::Node>> + Send;
}
impl<F, Target, Fut, Node> LaunchNode<Target> for F
where
F: FnOnce(Target) -> Fut + Send,
Fut: Future<Output = eyre::Result<Node>> + Send,
{
type Node = Node;
fn launch_node(self, target: Target) -> impl Future<Output = eyre::Result<Self::Node>> + Send {
self(target)
}
}
/// The default launcher for a node.
#[derive(Debug)]
pub struct DefaultNodeLauncher {