fxfs/
debug_assert_not_too_long.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#[macro_export]
6macro_rules! debug_assert_not_too_long {
7    ($future:expr $(, $arg:tt)*) => {
8        {
9            #[cfg(debug_assertions)]
10            {
11                use futures::future::FutureExt;
12                let future = $future.fuse();
13                futures::pin_mut!(future);
14                loop {
15                    futures::select! {
16                        () = fuchsia_async::Timer::new(std::time::Duration::from_secs(60)).fuse() =>
17                            {
18                                #[cfg(all(target_os = "fuchsia", not(doc)))]
19                                ::debug::backtrace_request_all_threads();
20                                #[cfg(not(target_os = "fuchsia"))]
21                                panic!($($arg),*);
22                            }
23                        result = future => break result,
24                    }
25                }
26            }
27            #[cfg(not(debug_assertions))]
28            $future.await
29        }
30    };
31}