1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::sync::Arc;
use crate::prelude::*;
use thirdparty::arrow_array::Array;
/// Typed Output to receive data from the dataflow
pub struct Output<T: ArrowMessage> {
pub raw: RawOutput,
_phantom: std::marker::PhantomData<T>,
}
impl<T: ArrowMessage> Output<T> {
/// Create a new typed Output from a MessageSender, NodeLayout, and OutputLayout
pub fn new(
tx: Vec<MessageSender>,
clock: Arc<HLC>,
source: NodeLayout,
layout: OutputLayout,
) -> Self {
Self {
raw: RawOutput::new(tx, clock, source, layout),
_phantom: std::marker::PhantomData,
}
}
/// Send a message to the output, blocking the current thread until the message is sent.
/// Don't use in async context
pub fn blocking_send(&self, data: T) -> Result<()> {
self.raw.blocking_send(
data.try_into_arrow()
.wrap_err(report_failed_conversion_to_arrow::<T>(
&self.raw.source,
&self.raw.layout,
))?
.into_data(),
)
}
/// Send a message to the output asynchronously.
pub async fn send(&self, data: T) -> Result<()> {
self.raw
.send(
data.try_into_arrow()
.wrap_err(report_failed_conversion_to_arrow::<T>(
&self.raw.source,
&self.raw.layout,
))?
.into_data(),
)
.await
}
}