Start working on plugin epoch async yield
This commit is contained in:
parent
8bcfcce506
commit
170d27b04c
2 changed files with 17 additions and 6 deletions
|
@ -60,7 +60,7 @@ fn main() {
|
||||||
fn create_default_engine() -> Engine {
|
fn create_default_engine() -> Engine {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.async_support(true);
|
config.async_support(true);
|
||||||
// config.epoch_interruption(true);
|
config.epoch_interruption(true);
|
||||||
Engine::new(&config).expect("Could not create engine")
|
Engine::new(&config).expect("Could not create engine")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub struct PluginBuilder {
|
||||||
pub fn create_default_engine() -> Result<Engine, Error> {
|
pub fn create_default_engine() -> Result<Engine, Error> {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.async_support(true);
|
config.async_support(true);
|
||||||
// config.epoch_interruption(true);
|
config.epoch_interruption(true);
|
||||||
Engine::new(&config)
|
Engine::new(&config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,11 +303,12 @@ impl Plugin {
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn init(
|
async fn init<T, F: Future<Output = ()> + Send + 'static>(
|
||||||
precompiled: bool,
|
precompiled: bool,
|
||||||
module: Vec<u8>,
|
module: Vec<u8>,
|
||||||
plugin: PluginBuilder,
|
plugin: PluginBuilder,
|
||||||
) -> Result<Self, Error> {
|
spawn_incrementer: impl Fn(F) -> T,
|
||||||
|
) -> Result<(Self, T), Error> {
|
||||||
// initialize the WebAssembly System Interface context
|
// initialize the WebAssembly System Interface context
|
||||||
let engine = plugin.engine;
|
let engine = plugin.engine;
|
||||||
let mut linker = plugin.linker;
|
let mut linker = plugin.linker;
|
||||||
|
@ -322,7 +323,8 @@ impl Plugin {
|
||||||
alloc: None,
|
alloc: None,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
// store.epoch_deadline_async_yield_and_update(todo!());
|
store.epoch_deadline_async_yield_and_update(1);
|
||||||
|
|
||||||
let module = if precompiled {
|
let module = if precompiled {
|
||||||
unsafe { Module::deserialize(&engine, module)? }
|
unsafe { Module::deserialize(&engine, module)? }
|
||||||
} else {
|
} else {
|
||||||
|
@ -342,7 +344,16 @@ impl Plugin {
|
||||||
free_buffer,
|
free_buffer,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(Plugin { store, instance })
|
let plugin = Plugin { store, instance };
|
||||||
|
let incrementer = spawn_incrementer(async move {
|
||||||
|
loop {
|
||||||
|
smol::Timer::after(std::time::Duration::from_millis(100)).await;
|
||||||
|
|
||||||
|
engine.increment_epoch();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok((plugin, incrementer))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attaches a file or directory the the given system path to the runtime.
|
/// Attaches a file or directory the the given system path to the runtime.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue