mirror of
https://github.com/servo/servo.git
synced 2025-09-30 00:29:14 +01:00
Add generic cross process callback mechanism (#38973)
One commonly encountered mechanism in servo is using ipc channels together with the router, to register a custom callback to run in the current process, when receiving a reply. The new `GenericCallback` abstracts over this, and allows executing an arbitrary callback in the process of the `GenericCallback` creator. In multiprocess mode, this internally uses ipc channels and follows the existing pattern. In single process mode, we execute the callback directly, which avoids one call to the router. Executing the callback still incurs synchronization, since we need to support cloning the abstraction, and the callback closure may be `FnMut`. Future work could provide more optimized abstractions for callbacks that don't have these requirements. This PR allows applying #38782 again, which was previously reverted in #38940 due to the lack of custom callback support. See also the module documentation in `generic_channel/callback.rs`. Testing: This PR adds unit tests. Also passes the manual testcase from #38939 Part of #38912 --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> Signed-off-by: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Co-authored-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
6565d982bd
commit
e5f9d81058
4 changed files with 366 additions and 20 deletions
|
@ -15,6 +15,9 @@ use serde::de::VariantAccess;
|
|||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use servo_config::opts;
|
||||
|
||||
mod callback;
|
||||
pub use callback::GenericCallback;
|
||||
|
||||
/// Abstraction of the ability to send a particular type of message cross-process.
|
||||
/// This can be used to ease the use of GenericSender sub-fields.
|
||||
pub trait GenericSend<T>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue