Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ features = [
'call-hook',
'memory-protection-keys',
'component-model-async',
'task-group-hook',
'component-model-bytes',
'gc-copying',
]
Expand Down
19 changes: 10 additions & 9 deletions crates/wasi-http/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::sync::{
use std::task::{Context, Poll};
use std::time::Instant;
use tokio::sync::Notify;
use wasmtime::component::{Accessor, GuestTaskId, Resource, TypedFuncCallConcurrent};
use wasmtime::component::{Accessor, Resource, TaskGroupId, TypedFuncCallConcurrent};
#[cfg(feature = "p2")]
use wasmtime::error::Context as _;
use wasmtime::{AsContextMut, Result, Store, StoreContextMut, format_err};
Expand Down Expand Up @@ -184,8 +184,9 @@ pub trait WorkerState: 'static + Send + Sync {
/// Notification that a request has been accepted by the worker.
///
/// This method can be used to record anything within `store`, if necessary.
/// The `task` corresponding to the component-model-level async task about
/// to be created is additionally passed here.
/// If the `task-group-hook` feature is enabled, the task group
/// corresponding to the component-model-level async task about to be
/// created is additionally passed here.
///
/// If the future returned by this function resolves before the guest has
/// produced a response, the request will be considered "expired" and the
Expand Down Expand Up @@ -217,7 +218,7 @@ pub trait WorkerState: 'static + Send + Sync {
&self,
store: StoreContextMut<'_, Self::StoreData>,
data: Self::RequestData,
task: GuestTaskId,
task_group: TaskGroupId,
) -> Pin<Box<dyn Future<Output = ()> + 'static + Send + Sync>>;

/// Dispose of the store belonging to the now-exited worker.
Expand Down Expand Up @@ -508,7 +509,7 @@ where
let expiration = dropper.state.on_request_start(
store.as_context_mut(),
request_data,
prepared.task(),
prepared.group(),
);
Ok((prepared, expiration))
}
Expand Down Expand Up @@ -948,7 +949,7 @@ where
}

/// Representation of a "prepared" call for a guest, used to extract the
/// `GuestTaskId` before actually executing any handlers.
/// `TaskGroupId` before actually executing any handlers.
///
/// Right now this is a bit gross since it has to type out a bunch of types by
/// hand.
Expand Down Expand Up @@ -1043,12 +1044,12 @@ impl<'a, T: Send> Prepared<'a, T> {
}
}

fn task(&self) -> GuestTaskId {
fn group(&self) -> TaskGroupId {
match self {
#[cfg(feature = "p3")]
Prepared::P3 { call, .. } => call.task(),
Prepared::P3 { call, .. } => call.group(),
#[cfg(feature = "p2")]
Prepared::P2 { call, .. } => call.task(),
Prepared::P2 { call, .. } => call.group(),
}
}

Expand Down
5 changes: 5 additions & 0 deletions crates/wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,8 @@ rr = [
"component-model",
"wasmtime-environ/rr"
]

# Enable support for the `Store::task_group_hook` function which registers a
# hook to be notified when host->guest task "groups" are created, entered,
# exited, and disposed of.
task-group-hook = [ "component-model", "component-model-async" ]
Comment thread
dicej marked this conversation as resolved.
Loading
Loading