mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added parallelism to event execution using rayon
This commit is contained in:
parent
cae81e625e
commit
b18eda37b5
@ -11,6 +11,8 @@ use plugin_api::Event;
|
||||
|
||||
use self::{ errors::PluginError, module::{PluginModule, PreparedEventQuery}};
|
||||
|
||||
use rayon::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct PluginData {
|
||||
name: String,
|
||||
@ -88,12 +90,9 @@ impl PluginMgr {
|
||||
}
|
||||
|
||||
pub fn execute_prepared<T>(&self, event_name: &str,event: &PreparedEventQuery<T>) -> Result<Vec<T::Response>, PluginError> where T: Event {
|
||||
let mut out = Vec::new();
|
||||
for plugin in &self.plugins {
|
||||
let exe = plugin.execute_prepared(event_name, event)?;
|
||||
out.extend(exe);
|
||||
}
|
||||
Ok(out)
|
||||
Ok(self.plugins.par_iter().map(|plugin| {
|
||||
plugin.execute_prepared(event_name, event)
|
||||
}).collect::<Result<Vec<_>,_>>()?.into_iter().flatten().collect())
|
||||
}
|
||||
|
||||
pub fn execute_event<T>(&self, event_name: &str,event: &T) -> Result<Vec<T::Response>, PluginError> where T: Event {
|
||||
|
@ -8,8 +8,8 @@ pub enum Action {
|
||||
KillEntity(usize)
|
||||
}
|
||||
|
||||
pub trait Event: Serialize + DeserializeOwned{
|
||||
type Response: Serialize + DeserializeOwned;
|
||||
pub trait Event: Serialize + DeserializeOwned + Send + Sync{
|
||||
type Response: Serialize + DeserializeOwned + Send + Sync;
|
||||
}
|
||||
|
||||
// TODO: Unify this with common/src/comp/uid.rs:Uid
|
||||
|
Loading…
Reference in New Issue
Block a user