some_executor 0.7.2

A trait for libraries that abstract over any executor
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0

use some_executor::{
    current_executor::current_executor,
    task::{Configuration, Task},
};
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll, Waker};

struct WakeThenFinish(bool);

impl Future for WakeThenFinish {
    type Output = ();

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
        if self.0 {
            Poll::Ready(())
        } else {
            self.0 = true;
            cx.waker().wake_by_ref();
            Poll::Pending
        }
    }
}

#[cfg_attr(target_arch = "wasm32", wasm_lite::wasm_lite_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn instrumentation_is_a_noop_without_a_runtime() {
    let task = Task::without_notifications(
        "no runtime".to_string(),
        Configuration::default(),
        WakeThenFinish(false),
    );
    let mut executor = current_executor();
    let (spawned, observer) = task.spawn(&mut executor);
    let mut spawned = Box::pin(spawned);
    let mut cx = Context::from_waker(Waker::noop());
    assert!(Future::poll(spawned.as_mut(), &mut cx).is_pending());
    assert!(Future::poll(spawned.as_mut(), &mut cx).is_ready());
    assert_eq!(logwise::context::capture(), logwise::ContextToken::NONE);
    drop(observer);
}