-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(katana-node): distinguish between launched node handle (#2504)
abstraction to distinguish between a launched and not yet launch node handle. also appropriately place the stop methods under the launched handle. this PR also includes some ergonomic changes to some of the futures used to stop the node. having a different struct for this would allow conveying to the readers that the node can either be in static (not yet launched) and already launched node. and thus only expose certain methods based on the appropriate handle. eg, the LaunchedNode::stop() method is placed under LaunchedNode because you can only stop node that has been started. it doesn't make sense to stop a node that hasn't even been ran.
- Loading branch information
Showing
8 changed files
with
221 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
use anyhow::Result; | ||
use futures::future::BoxFuture; | ||
use futures::FutureExt; | ||
|
||
use crate::LaunchedNode; | ||
|
||
/// A Future that is resolved once the node has been stopped including all of its running tasks. | ||
#[must_use = "futures do nothing unless polled"] | ||
pub struct NodeStoppedFuture<'a> { | ||
fut: BoxFuture<'a, Result<()>>, | ||
} | ||
|
||
impl<'a> NodeStoppedFuture<'a> { | ||
pub(crate) fn new(handle: &'a LaunchedNode) -> Self { | ||
let fut = Box::pin(async { | ||
handle.node.task_manager.wait_for_shutdown().await; | ||
handle.stop().await?; | ||
Ok(()) | ||
}); | ||
Self { fut } | ||
} | ||
} | ||
|
||
impl<'a> Future for NodeStoppedFuture<'a> { | ||
type Output = Result<()>; | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = self.get_mut(); | ||
this.fut.poll_unpin(cx) | ||
} | ||
} | ||
|
||
impl<'a> core::fmt::Debug for NodeStoppedFuture<'a> { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
f.debug_struct("NodeStoppedFuture").field("fut", &"...").finish() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
3e51d5d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.30
.Concurrent.Simulate/Blockifier.1000
3532479541
ns/iter (± 787487385
)2685904660
ns/iter (± 244740276
)1.32
This comment was automatically generated by workflow using github-action-benchmark.
CC: @kariy @glihm @tarrencev