Files
servo/components/shared/profile/generic_callback.rs
Narfinger a841eb49d5 IndexedDB: Use GenericSender, GenericReceiver and GenericCallback for IndexedDB (#41031)
Moving IndexedDB to use the generic channel methods.

Of note is the change in 'IDBRequest::execute_async'. This method
previously added a channel that was constructed from the callsite in put
into the AsyncOperation. Now we do not take a function but take a
'FnOnce(GenericCallback<BackendResult<T>>) -> AsyncOperation'. With this
the callsite can construct the AsyncOperation to give in the
'IndexedDBThreadMsg::Async'.

The rest are mostly just type changes.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: WPT tests on the IndexedDB subset still pass.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-12-04 05:25:17 +00:00

43 lines
1.2 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use base::generic_channel::SendResult;
use serde::{Deserialize, Serialize};
use crate::time::{ProfilerCategory, ProfilerChan};
use crate::time_profile;
#[derive(Debug, Serialize, Deserialize)]
pub struct GenericCallback<T>
where
T: Serialize + Send + 'static,
{
callback: base::generic_channel::GenericCallback<T>,
time_profiler_chan: ProfilerChan,
}
impl<T> GenericCallback<T>
where
T: for<'de> Deserialize<'de> + Serialize + Send + 'static,
{
pub fn new<F: FnMut(Result<T, ipc_channel::Error>) + Send + 'static>(
time_profiler_chan: ProfilerChan,
callback: F,
) -> Result<Self, ipc_channel::Error> {
Ok(GenericCallback {
callback: base::generic_channel::GenericCallback::new(callback)?,
time_profiler_chan,
})
}
pub fn send(&self, value: T) -> SendResult {
time_profile!(
ProfilerCategory::IpcReceiver,
None,
self.time_profiler_chan.clone(),
move || self.callback.send(value)
)
}
}