diff --git a/crates/ark/src/interface.rs b/crates/ark/src/interface.rs index c0aafafae..553e01481 100644 --- a/crates/ark/src/interface.rs +++ b/crates/ark/src/interface.rs @@ -387,7 +387,13 @@ impl RMain { .or_log_error(&format!("Failed to source startup file '{file}' due to")); } - // Initialize support functions (after routine registration) + // R and ark are now set up enough to allow interrupt-time and idle-time tasks + // to be sent through. Idle-time tasks will be run once we enter + // `read_console()` for the first time. Interrupt-time tasks could be run + // sooner if we hit a check-interrupt before then. + r_task::initialize(tasks_interrupt_tx, tasks_idle_tx); + + // Initialize support functions (after routine registration, after r_task initialization) match modules::initialize() { Err(err) => { log::error!("Can't load R modules: {err:?}"); @@ -405,6 +411,7 @@ impl RMain { // Populate srcrefs for namespaces already loaded in the session. // Namespaces of future loaded packages will be populated on load. + // (after r_task initialization) if do_resource_namespaces() { if let Err(err) = resource_loaded_namespaces() { log::error!("Can't populate srcrefs for loaded packages: {err:?}"); @@ -414,9 +421,6 @@ impl RMain { // Set up the global error handler (after support function initialization) errors::initialize(); - // Now allow interrupt-time tasks to run - r_task::initialize(tasks_interrupt_tx, tasks_idle_tx); - // Now that R has started (emitting any startup messages), and now that we have set // up all hooks and handlers, officially finish the R initialization process to // unblock the kernel-info request and also allow the LSP to start. diff --git a/crates/ark/src/r_task.rs b/crates/ark/src/r_task.rs index 5d6f8c7e6..cd56f6dd7 100644 --- a/crates/ark/src/r_task.rs +++ b/crates/ark/src/r_task.rs @@ -232,7 +232,6 @@ where return result.lock().unwrap().take().unwrap(); } -#[allow(dead_code)] // Currently unused pub(crate) fn spawn_idle(fun: F) where F: FnOnce() -> Fut + 'static + Send, @@ -261,6 +260,8 @@ where return; } + // Note that this blocks until the channels are initialized, + // even though these are async tasks! let tasks_tx = if only_idle { get_tasks_idle_tx() } else {