PollInput implementation

This commit is contained in:
Zachary Sunforge
2023-06-23 16:55:33 -07:00
parent 07cb49bee5
commit 2a0013481c
6 changed files with 97 additions and 24 deletions

View File

@ -142,6 +142,8 @@ pub fn poll_variant_macro(input: TokenStream) -> TokenStream {
let publisher_path: Path = parse_quote!(physical_node::transducer::Publisher);
let cellview_path: Path = parse_quote!(physical_node::cell::CellView);
let error_path: Path = parse_quote!(physical_node::CriticalError);
let expanded = quote! {
// ----- Stateful struct ----------------------------------
#vis struct #stateful_variant_ident #og_generics #og_where_clause {
@ -153,11 +155,13 @@ pub fn poll_variant_macro(input: TokenStream) -> TokenStream {
impl #og_impl_generics #poll_path for #stateful_variant_ident #og_type_generics #og_where_clause {
type Value = #value_type_path;
#[inline(always)]
async fn poll(&self) -> Self::Value {
let value = self.poll.poll().await;
self.state.update(value);
value
#[inline]
async fn poll(&self) -> Result<Self::Value, #error_path> {
let result = self.poll.poll().await;
if let Ok(value) = result {
self.state.update(value);
}
result
}
}
@ -187,11 +191,13 @@ pub fn poll_variant_macro(input: TokenStream) -> TokenStream {
impl #publ_impl_generics #poll_path for #publish_variant_ident #publ_type_generics #publ_where_clause {
type Value = #value_type_path;
#[inline(always)]
async fn poll(&self) -> Self::Value {
let value = self.poll.poll().await;
self.publisher.update(value);
value
#[inline]
async fn poll(&self) -> Result<Self::Value, #error_path> {
let result = self.poll.poll().await;
if let Ok(value) = result {
self.publisher.update(value);
}
result
}
}
@ -221,11 +227,13 @@ pub fn poll_variant_macro(input: TokenStream) -> TokenStream {
type Value = #value_type_path;
#[inline]
async fn poll(&self) -> Self::Value {
let value = self.poll.poll().await;
self.state.update(value);
self.publisher.update(value);
value
async fn poll(&self) -> Result<Self::Value, #error_path> {
let result = self.poll.poll().await;
if let Ok(value) = result {
self.state.update(value);
self.publisher.update(value);
}
result
}
}

View File

@ -1,6 +1,7 @@
#![feature(async_fn_in_trait, impl_trait_projections)]
use node_poll_variants::PollVariants;
use physical_node::CriticalError;
use physical_node::transducer::input::Poll;
#[derive(PollVariants)]
@ -21,8 +22,8 @@ where
{
type Value = SecondT;
async fn poll(&self) -> Self::Value {
self.second
async fn poll(&self) -> Result<Self::Value, CriticalError> {
Ok(self.second)
}
}