summaryrefslogtreecommitdiff
path: root/core/task.rs
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-05-17 15:49:57 -0600
committerGitHub <noreply@github.com>2023-05-17 15:49:57 -0600
commit62e779f82d7c9427c33484baa676c09a1917b0d6 (patch)
tree18ef92445e759d5b4a3e4387e3b9f0cf7483baf5 /core/task.rs
parent41f618a1df6bb8c66d7968ac64456139b9f4c197 (diff)
fix(runtime): Box the main future to avoid blowing up the stack (#19155)
This fixes `Unhandled exception at [...] Stack overflow` on Windows, caused by the large size of the main future.
Diffstat (limited to 'core/task.rs')
-rw-r--r--core/task.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/core/task.rs b/core/task.rs
index 46a4c8c26..3e728a08f 100644
--- a/core/task.rs
+++ b/core/task.rs
@@ -44,6 +44,7 @@ impl<R> Future for JoinHandle<R> {
/// Equivalent to [`tokio::task::spawn`], but does not require the future to be [`Send`]. Must only be
/// used on a [`RuntimeFlavor::CurrentThread`] executor, though this is only checked when running with
/// debug assertions.
+#[inline(always)]
pub fn spawn<F: Future<Output = R> + 'static, R: 'static>(
f: F,
) -> JoinHandle<R> {
@@ -60,6 +61,7 @@ pub fn spawn<F: Future<Output = R> + 'static, R: 'static>(
/// Equivalent to [`tokio::task::spawn_blocking`]. Currently a thin wrapper around the tokio API, but this
/// may change in the future.
+#[inline(always)]
pub fn spawn_blocking<
F: (FnOnce() -> R) + Send + 'static,
R: Send + 'static,
@@ -89,6 +91,7 @@ impl<R> MaskResultAsSend<R> {
}
}
+#[repr(transparent)]
pub struct MaskFutureAsSend<F> {
future: F,
}
@@ -102,6 +105,7 @@ impl<F> MaskFutureAsSend<F> {
///
/// You must ensure that the future is actually used on the same
/// thread, ie. always use current thread runtime flavor from Tokio.
+ #[inline(always)]
pub unsafe fn new(future: F) -> Self {
Self { future }
}