pub struct Task;Expand description
One current span per task.
A task gets its own slot by running inside Task::scope; outside a
scope there is no current span and Storage::set does nothing.
PHP: Utopia\Span\Storage\Coroutine, which keeps the span in the Swoole
coroutine’s context (Coroutine::getContext()); a scope is a coroutine.
use utopia_span::{Span, Storage, Task};
let storage = Task::new();
storage.set(Some(Span::new("ignored")));
assert!(storage.get().is_none()); // outside a scope
Task::scope(async {
let storage = Task::new();
let span = Span::new("request");
storage.set(Some(span.clone()));
assert_eq!(storage.get(), Some(span));
})
.await;use Utopia\Span\Span;
use Utopia\Span\Storage\Coroutine;
$storage = new Coroutine();
$storage->set(new Span('ignored'));
var_dump($storage->get()); // NULL: outside a coroutine
\Swoole\Coroutine\run(function () {
$storage = new Coroutine();
$span = new Span('request');
$storage->set($span);
var_dump($storage->get() === $span); // bool(true)
});Implementations§
Source§impl Task
impl Task
Sourcepub fn scope<F: Future>(future: F) -> impl Future<Output = F::Output>
pub fn scope<F: Future>(future: F) -> impl Future<Output = F::Output>
Runs future with its own current-span slot, initially empty.
PHP: running code in a new Swoole coroutine.
Sourcepub fn sync_scope<R>(f: impl FnOnce() -> R) -> R
pub fn sync_scope<R>(f: impl FnOnce() -> R) -> R
Runs f synchronously with its own current-span slot.
Sourcepub fn in_scope() -> bool
pub fn in_scope() -> bool
Whether the caller runs inside a Task::scope.
PHP: Coroutine::getCid() !== -1.
Trait Implementations§
impl Copy for Task
Auto Trait Implementations§
impl Forget for Task
impl Freeze for Task
impl Move for Task
impl RefUnwindSafe for Task
impl Send for Task
impl Sync for Task
impl Unpin for Task
impl UnsafeUnpin for Task
impl UnwindSafe for Task
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more