use std::pin::Pin;
use bytes::Bytes;
use futures::Future;
use wasmer_wasix_types::{
wasi::Errno,
wasix::{ThreadStartType, WasiMemoryLayout},
};
use crate::os::task::thread::RewindResultType;
#[doc(hidden)]
pub type AsyncifyFuture = dyn Future<Output = Bytes> + Send + Sync + 'static;
pub trait RewindPostProcess {
fn finish(&mut self, res: Result<(), Errno>) -> Bytes;
}
pub struct RewindState {
pub memory_stack: Bytes,
pub rewind_stack: Bytes,
pub store_data: Bytes,
pub start: ThreadStartType,
pub layout: WasiMemoryLayout,
pub is_64bit: bool,
}
pub type RewindStateOption = Option<(RewindState, RewindResultType)>;
pub struct DeepSleepWork {
pub trigger: Pin<Box<AsyncifyFuture>>,
pub rewind: RewindState,
}
impl std::fmt::Debug for DeepSleepWork {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"deep-sleep-work(memory_stack_len={}, rewind_stack_len={}, store_size={})",
self.rewind.memory_stack.len(),
self.rewind.rewind_stack.len(),
self.rewind.store_data.len()
)
}
}