Download next.js/turbopack/crates/turbo-tasks/src/scope.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbo-tasks/src/scope.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbo-tasks/src/scope.rs
-
curl -L -o scope.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbo-tasks/src/scope.rs
1.46 kB
| use std::sync::Arc; | |
| use crate::{TurboTasksApi, turbo_tasks, turbo_tasks_scope}; | |
| /// A wrapper around [`rayon::Scope`] that preserves the [`turbo_tasks_scope`]. | |
| pub struct Scope<'scope, 'a> { | |
| scope: &'a rayon::Scope<'scope>, | |
| handle: tokio::runtime::Handle, | |
| turbo_tasks: Arc<dyn TurboTasksApi>, | |
| span: tracing::Span, | |
| } | |
| impl<'scope> Scope<'scope, '_> { | |
| pub fn spawn<Body>(&self, body: Body) | |
| where | |
| Body: FnOnce(&Scope<'scope, '_>) + Send + 'scope, | |
| { | |
| let span = self.span.clone(); | |
| let handle = self.handle.clone(); | |
| let turbo_tasks = self.turbo_tasks.clone(); | |
| self.scope.spawn(|scope| { | |
| let _span = span.clone().entered(); | |
| let _guard = handle.enter(); | |
| turbo_tasks_scope(turbo_tasks.clone(), || { | |
| body(&Scope { | |
| scope, | |
| span, | |
| handle, | |
| turbo_tasks, | |
| }) | |
| }) | |
| }); | |
| } | |
| } | |
| /// A wrapper around [`rayon::in_place_scope`] that preserves the [`turbo_tasks_scope`]. | |
| pub fn scope<'scope, Op, R>(op: Op) -> R | |
| where | |
| Op: FnOnce(&Scope<'scope, '_>) -> R, | |
| { | |
| let span = tracing::Span::current(); | |
| let handle = tokio::runtime::Handle::current(); | |
| let turbo_tasks = turbo_tasks(); | |
| rayon::in_place_scope(|scope| { | |
| op(&Scope { | |
| scope, | |
| span, | |
| handle, | |
| turbo_tasks, | |
| }) | |
| }) | |
| } | |