Skip to content

Commit 0802ecd

Browse files
authored
feat: recorder graceful drop (#2327)
1 parent 8291172 commit 0802ecd

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

lib/llm/src/recorder.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
//
4-
// Licensed under the Apache License, Version 2.0 (the "License");
5-
// you may not use this file except in compliance with the License.
6-
// You may obtain a copy of the License at
7-
//
8-
// http://www.apache.org/licenses/LICENSE-2.0
9-
//
10-
// Unless required by applicable law or agreed to in writing, software
11-
// distributed under the License is distributed on an "AS IS" BASIS,
12-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
// See the License for the specific language governing permissions and
14-
// limitations under the License.
153

164
use serde::{Deserialize, Serialize};
175
use std::io;
@@ -386,6 +374,12 @@ where
386374
}
387375
}
388376

377+
impl<T> Drop for Recorder<T> {
378+
fn drop(&mut self) {
379+
self.cancel.cancel();
380+
}
381+
}
382+
389383
/// Helper function to create a rotated file path with an index suffix
390384
fn create_rotated_path(base_path: &Path, index: usize) -> PathBuf {
391385
let path_str = base_path.to_string_lossy();
@@ -471,11 +465,11 @@ mod tests {
471465
// Check that both events were recorded
472466
assert_eq!(recorder.event_count().await, 2);
473467

474-
// Check that the elapsed time is between 9 and 11 milliseconds
468+
// Check that the elapsed time is between 7 and 13 milliseconds
475469
let elapsed_ms = recorder.elapsed_time().await.unwrap().as_millis();
476-
if !(9..=11).contains(&elapsed_ms) {
470+
if !(7..=13).contains(&elapsed_ms) {
477471
println!("Actual elapsed time: {} ms", elapsed_ms);
478-
assert!((9..=11).contains(&elapsed_ms));
472+
assert!((7..=13).contains(&elapsed_ms));
479473
}
480474

481475
// Force shutdown to flush file

0 commit comments

Comments
 (0)