Skip to content

Commit

Permalink
Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
aurexav committed Dec 31, 2024
1 parent 0ba3339 commit 6be4cee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 3 additions & 3 deletions substrate/utils/frame/remote-externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,8 @@ where
},
})
.collect::<Vec<_>>();
// Must succeed; qed.
let _ = logging::with_elapsed(

logging::with_elapsed(
|| {
pending_ext.batch_insert(key_values.clone().into_iter().filter_map(|(k, v)| {
// Don't insert the child keys here, they need to be inserted separately with
Expand All @@ -774,7 +774,7 @@ where
},
"Inserting keys into DB...",
|_| "Inserted keys into DB".into(),
);
).expect("must succeed; qed");

Ok(key_values)
}
Expand Down
29 changes: 28 additions & 1 deletion substrate/utils/frame/remote-externalities/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{
future::Future,
io::{self, IsTerminal},
Expand All @@ -8,6 +25,9 @@ use spinners::{Spinner, Spinners};

use super::Result;

// A simple helper to time an async operation with a nice spinner, start message, and end message.
//
// The spinner is only displayed when stdout is a terminal.
pub(super) fn with_elapsed<F, R, EndMsg>(f: F, start_msg: &str, end_msg: EndMsg) -> Result<R>
where
F: FnOnce() -> Result<R>,
Expand All @@ -23,7 +43,14 @@ where
}
}

pub(super) async fn with_elapsed_async<F, Fut, R, EndMsg>(f: F, start_msg: &str, end_msg: EndMsg) -> Result<R>
// A simple helper to time a operation with a nice spinner, start message, and end message.
//
// The spinner is only displayed when stdout is a terminal.
pub(super) async fn with_elapsed_async<F, Fut, R, EndMsg>(
f: F,
start_msg: &str,
end_msg: EndMsg,
) -> Result<R>
where
F: FnOnce() -> Fut,
Fut: Future<Output = Result<R>>,
Expand Down

0 comments on commit 6be4cee

Please sign in to comment.