-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for clients and services
- Loading branch information
Showing
21 changed files
with
851 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// Based on https://www.viget.com/articles/understanding-futures-in-rust-part-1/ | ||
use core::marker::PhantomData; | ||
use parking_lot::Mutex; | ||
use std::future::Future; | ||
use std::pin::Pin; | ||
use std::sync::Arc; | ||
use std::task::Context; | ||
use std::task::Poll; | ||
|
||
#[derive(Default)] | ||
pub struct RclFuture<T> { | ||
value: Option<T>, | ||
} | ||
|
||
impl<T: Default + Clone> RclFuture<T> { | ||
pub fn new() -> RclFuture<T> { | ||
Self { value: None } | ||
} | ||
|
||
pub fn set_value(&mut self, msg: T) { | ||
self.value = Some(msg); | ||
} | ||
} | ||
|
||
impl<T: Clone> Future for RclFuture<T> { | ||
type Output = T; | ||
|
||
fn poll(self: Pin<&mut Self>, _ctx: &mut Context) -> Poll<Self::Output> { | ||
if let Some(value) = &self.value { | ||
Poll::Ready(value.clone()) | ||
} else { | ||
Poll::Pending | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.