Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions turbopack/crates/turbo-tasks/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,17 @@ impl<'scope, 'env: 'scope, R: Send + 'env> Scope<'scope, 'env, R> {
assert!(index < self.results.len(), "Too many tasks spawned");
let result_cell: &Mutex<Option<R>> = &self.results[index];

let turbo_tasks = self.turbo_tasks.clone();
let f: Box<dyn FnOnce() + Send + 'scope> = Box::new(|| {
let result = f();
let result = {
if let Some(turbo_tasks) = turbo_tasks {
// Ensure that the turbo tasks context is maintained across the job.
turbo_tasks_scope(turbo_tasks, f)
} else {
// If no turbo tasks context is available, just run the job.
f()
}
};
*result_cell.lock() = Some(result);
});
let f: *mut (dyn FnOnce() + Send + 'scope) = Box::into_raw(f);
Expand All @@ -210,7 +219,6 @@ impl<'scope, 'env: 'scope, R: Send + 'env> Scope<'scope, 'env, R> {
// SAFETY: We just called `Box::into_raw`.
let f = unsafe { Box::from_raw(f) };

let turbo_tasks = self.turbo_tasks.clone();
let span = self.span.clone();

self.inner.remaining_tasks.fetch_add(1, Ordering::Relaxed);
Expand All @@ -223,15 +231,7 @@ impl<'scope, 'env: 'scope, R: Send + 'env> Scope<'scope, 'env, R> {
// Spawn a worker task that will process that tasks and potentially more.
self.handle.spawn(async move {
let _span = span.entered();
if let Some(turbo_tasks) = turbo_tasks {
// Ensure that the turbo tasks context is maintained across the worker.
turbo_tasks_scope(turbo_tasks, || {
inner.worker(index, f);
});
} else {
// If no turbo tasks context is available, just run the worker.
inner.worker(index, f);
}
inner.worker(index, f);
});
} else {
// Queue the task to be processed by a worker task.
Expand Down
Loading