mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-07-10 15:59:32 +00:00
refactor(indexer): auto-cancel token on Drop
This commit is contained in:
parent
15512a4c97
commit
0f15c60cd0
@ -88,7 +88,7 @@ pub async fn run_server(
|
||||
|
||||
#[cfg(not(feature = "mock-responses"))]
|
||||
let handle = {
|
||||
let service = service::IndexerService::new(config, storage_dir, shutdown)
|
||||
let service = service::IndexerService::new(config, storage_dir, shutdown.child_token())
|
||||
.await
|
||||
.context("Failed to initialize indexer service")?;
|
||||
server.start(service.into_rpc())
|
||||
|
||||
@ -175,6 +175,10 @@ impl indexer_service_rpc::RpcServer for IndexerService {
|
||||
struct SubscriptionService {
|
||||
parts: ArcSwap<SubscriptionLoopParts>,
|
||||
indexer: IndexerCore,
|
||||
/// Cancellation token that is used to signal the subscription service to shut down.
|
||||
///
|
||||
/// NOTE: This will auto-cancel on `Drop`, so if your token is shared with other parts
|
||||
/// use [`CancellationToken::child_token()`] instead.
|
||||
shutdown: CancellationToken,
|
||||
}
|
||||
|
||||
@ -292,6 +296,7 @@ impl SubscriptionService {
|
||||
|
||||
impl Drop for SubscriptionService {
|
||||
fn drop(&mut self) {
|
||||
self.shutdown.cancel();
|
||||
self.parts.load().handle.abort();
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,8 @@ async fn main() -> Result<()> {
|
||||
|
||||
let Args { config_path, port } = Args::parse();
|
||||
|
||||
// TODO: handle this cancellation token more gracefully within Sequencer service
|
||||
// similar to how we do in Indexer
|
||||
let cancellation_token = listen_for_shutdown_signal();
|
||||
|
||||
let config = sequencer_service::SequencerConfig::from_path(&config_path)?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user