implement table _async methods, test passes now
This commit is contained in:
@@ -436,6 +436,31 @@ impl Table {
|
||||
Table::_new(store.as_context_mut().0, ty, init)
|
||||
}
|
||||
|
||||
/// Async variant of [`Table::new`]. You must use this variant with [`Store`]s which have a
|
||||
/// [`ResourceLimiterAsync`].
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic when used with a non-async [`Store`].
|
||||
#[cfg(feature = "async")]
|
||||
pub async fn new_async<T>(
|
||||
mut store: impl AsContextMut<Data = T>,
|
||||
ty: TableType,
|
||||
init: Val,
|
||||
) -> Result<Table>
|
||||
where
|
||||
T: Send,
|
||||
{
|
||||
let mut store = store.as_context_mut();
|
||||
assert!(
|
||||
store.0.async_support(),
|
||||
"cannot use `new_async` without enabling async support on the config"
|
||||
);
|
||||
store
|
||||
.on_fiber(|store| Table::_new(store.0, ty, init))
|
||||
.await?
|
||||
}
|
||||
|
||||
fn _new(store: &mut StoreOpaque, ty: TableType, init: Val) -> Result<Table> {
|
||||
let wasmtime_export = generate_table_export(store, &ty)?;
|
||||
let init = init.into_table_element(store, ty.element())?;
|
||||
@@ -562,6 +587,31 @@ impl Table {
|
||||
}
|
||||
}
|
||||
|
||||
/// Async variant of [`Table::grow`]. Required when using a [`ResourceLimiterAsync`].
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic when used with a non-async [`Store`].
|
||||
#[cfg(feature = "async")]
|
||||
pub async fn grow_async<T>(
|
||||
&self,
|
||||
mut store: impl AsContextMut<Data = T>,
|
||||
delta: u32,
|
||||
init: Val,
|
||||
) -> Result<u32>
|
||||
where
|
||||
T: Send,
|
||||
{
|
||||
let mut store = store.as_context_mut();
|
||||
assert!(
|
||||
store.0.async_support(),
|
||||
"cannot use `grow_async` without enabling async support on the config"
|
||||
);
|
||||
store
|
||||
.on_fiber(|store| self.grow(store, delta, init))
|
||||
.await?
|
||||
}
|
||||
|
||||
/// Copy `len` elements from `src_table[src_index..]` into
|
||||
/// `dst_table[dst_index..]`.
|
||||
///
|
||||
|
||||
@@ -134,19 +134,21 @@ async fn test_limits_async() -> Result<()> {
|
||||
// Test instance exports and host objects hitting the limit
|
||||
for table in std::array::IntoIter::new([
|
||||
instance.get_table(&mut store, "t").unwrap(),
|
||||
Table::new(
|
||||
Table::new_async(
|
||||
&mut store,
|
||||
TableType::new(ValType::FuncRef, 0, None),
|
||||
Val::FuncRef(None),
|
||||
)?,
|
||||
)
|
||||
.await?,
|
||||
]) {
|
||||
table.grow(&mut store, 2, Val::FuncRef(None))?;
|
||||
table.grow(&mut store, 1, Val::FuncRef(None))?;
|
||||
table.grow(&mut store, 2, Val::FuncRef(None))?;
|
||||
table.grow_async(&mut store, 2, Val::FuncRef(None)).await?;
|
||||
table.grow_async(&mut store, 1, Val::FuncRef(None)).await?;
|
||||
table.grow_async(&mut store, 2, Val::FuncRef(None)).await?;
|
||||
|
||||
assert_eq!(
|
||||
table
|
||||
.grow(&mut store, 1, Val::FuncRef(None))
|
||||
.grow_async(&mut store, 1, Val::FuncRef(None))
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
.unwrap_err(),
|
||||
"failed to grow table by `1`"
|
||||
|
||||
Reference in New Issue
Block a user