/* 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; use serde::{Deserialize, Serialize}; use crate::time::{ProfilerCategory, ProfilerChan}; use crate::time_profile; pub struct GenericReceiver where T: for<'de> Deserialize<'de> + Serialize, { receiver: generic_channel::GenericReceiver, time_profile_chan: ProfilerChan, } impl GenericReceiver where T: for<'de> Deserialize<'de> + Serialize, { pub fn recv(&self) -> Result { time_profile!( ProfilerCategory::IpcReceiver, None, self.time_profile_chan.clone(), move || self.receiver.recv(), ) } pub fn try_recv(&self) -> Result { self.receiver.try_recv() } pub fn into_inner(self) -> generic_channel::GenericReceiver { self.receiver } } pub fn channel( time_profile_chan: ProfilerChan, ) -> Option<(generic_channel::GenericSender, GenericReceiver)> where T: for<'de> Deserialize<'de> + Serialize, { let (sender, receiver) = generic_channel::channel()?; let profiled_receiver = GenericReceiver { receiver, time_profile_chan, }; Some((sender, profiled_receiver)) }