|
|
@ -1,20 +1,20 @@
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::mem;
|
|
|
|
use std::mem;
|
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
|
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
|
|
use tokio::sync::{Mutex, oneshot, RwLock};
|
|
|
|
use tokio::sync::oneshot::{Receiver, Sender};
|
|
|
|
use tokio::sync::oneshot::{Sender, Receiver};
|
|
|
|
use tokio::sync::{oneshot, Mutex, RwLock};
|
|
|
|
use tokio::time::Duration;
|
|
|
|
use tokio::time::Duration;
|
|
|
|
use typemap_rev::TypeMap;
|
|
|
|
use typemap_rev::TypeMap;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::error::{Error, Result};
|
|
|
|
use crate::error::{Error, Result};
|
|
|
|
use crate::event::Event;
|
|
|
|
use crate::event::{Event, EventType};
|
|
|
|
use crate::ipc::stream_emitter::{EmitMetadata, StreamEmitter};
|
|
|
|
use crate::ipc::stream_emitter::{EmitMetadata, StreamEmitter};
|
|
|
|
|
|
|
|
use crate::payload::IntoPayload;
|
|
|
|
#[cfg(feature = "serialize")]
|
|
|
|
#[cfg(feature = "serialize")]
|
|
|
|
use crate::payload::{DynamicSerializer, SerdePayload};
|
|
|
|
use crate::payload::{DynamicSerializer, SerdePayload};
|
|
|
|
use crate::payload::IntoPayload;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) type ReplyListeners = Arc<Mutex<HashMap<u64, oneshot::Sender<Event>>>>;
|
|
|
|
pub(crate) type ReplyListeners = Arc<Mutex<HashMap<u64, oneshot::Sender<Event>>>>;
|
|
|
|
|
|
|
|
|
|
|
@ -71,12 +71,26 @@ impl Context {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Emits an event with a given payload that can be serialized into bytes
|
|
|
|
/// Emits a raw event. Only for internal use
|
|
|
|
pub fn emit<S: AsRef<str>, P: IntoPayload>(
|
|
|
|
pub(crate) fn emit_raw<P: IntoPayload>(
|
|
|
|
&self,
|
|
|
|
&self,
|
|
|
|
name: S,
|
|
|
|
name: &str,
|
|
|
|
|
|
|
|
namespace: Option<String>,
|
|
|
|
|
|
|
|
event_type: EventType,
|
|
|
|
payload: P,
|
|
|
|
payload: P,
|
|
|
|
) -> EmitMetadata<P> {
|
|
|
|
) -> EmitMetadata<P> {
|
|
|
|
|
|
|
|
self.emitter.emit_raw(
|
|
|
|
|
|
|
|
self.clone(),
|
|
|
|
|
|
|
|
self.ref_id.clone(),
|
|
|
|
|
|
|
|
name,
|
|
|
|
|
|
|
|
namespace,
|
|
|
|
|
|
|
|
event_type,
|
|
|
|
|
|
|
|
payload,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Emits an event with a given payload that can be serialized into bytes
|
|
|
|
|
|
|
|
pub fn emit<S: AsRef<str>, P: IntoPayload>(&self, name: S, payload: P) -> EmitMetadata<P> {
|
|
|
|
if let Some(ref_id) = &self.ref_id {
|
|
|
|
if let Some(ref_id) = &self.ref_id {
|
|
|
|
self.emitter
|
|
|
|
self.emitter
|
|
|
|
.emit_response(self.clone(), *ref_id, name, payload)
|
|
|
|
.emit_response(self.clone(), *ref_id, name, payload)
|
|
|
@ -149,16 +163,16 @@ pub struct PooledContext {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub struct PoolGuard<T>
|
|
|
|
pub struct PoolGuard<T>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
T: Clone,
|
|
|
|
T: Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
inner: T,
|
|
|
|
inner: T,
|
|
|
|
count: Arc<AtomicUsize>,
|
|
|
|
count: Arc<AtomicUsize>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<T> Deref for PoolGuard<T>
|
|
|
|
impl<T> Deref for PoolGuard<T>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
T: Clone,
|
|
|
|
T: Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
type Target = T;
|
|
|
|
type Target = T;
|
|
|
|
|
|
|
|
|
|
|
@ -169,8 +183,8 @@ impl<T> Deref for PoolGuard<T>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<T> DerefMut for PoolGuard<T>
|
|
|
|
impl<T> DerefMut for PoolGuard<T>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
T: Clone,
|
|
|
|
T: Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
#[inline]
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
@ -179,8 +193,8 @@ impl<T> DerefMut for PoolGuard<T>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<T> Clone for PoolGuard<T>
|
|
|
|
impl<T> Clone for PoolGuard<T>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
T: Clone,
|
|
|
|
T: Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
#[inline]
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
@ -194,8 +208,8 @@ impl<T> Clone for PoolGuard<T>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<T> Drop for PoolGuard<T>
|
|
|
|
impl<T> Drop for PoolGuard<T>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
T: Clone,
|
|
|
|
T: Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
#[inline]
|
|
|
|
fn drop(&mut self) {
|
|
|
|
fn drop(&mut self) {
|
|
|
@ -204,8 +218,8 @@ impl<T> Drop for PoolGuard<T>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<T> PoolGuard<T>
|
|
|
|
impl<T> PoolGuard<T>
|
|
|
|
where
|
|
|
|
where
|
|
|
|
T: Clone,
|
|
|
|
T: Clone,
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pub(crate) fn new(inner: T) -> Self {
|
|
|
|
pub(crate) fn new(inner: T) -> Self {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|