Skip to content

Commit

Permalink
Fix r_task::initialize() timing issue (#566)
Browse files Browse the repository at this point in the history
* Remove inaccurate `dead_code` allowance

* Add comment

* Fix timing of `r_task::initialize()`

And document some things that rely on it
  • Loading branch information
DavisVaughan authored Oct 4, 2024
1 parent afc56d7 commit c16fc33
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions crates/ark/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand All @@ -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:?}");
Expand All @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion crates/ark/src/r_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ where
return result.lock().unwrap().take().unwrap();
}

#[allow(dead_code)] // Currently unused
pub(crate) fn spawn_idle<F, Fut>(fun: F)
where
F: FnOnce() -> Fut + 'static + Send,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c16fc33

Please sign in to comment.