mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add launch_with_fn (#8694)
This commit is contained in:
@ -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.
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user