mz_timely_util/
event.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License in the LICENSE file at the
6// root of this repository, or online at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Traits and types for describing captured timely dataflow streams.
17//!
18//! This is roughly based on [timely::dataflow::operators::capture::event].
19
20use timely::dataflow::operators::capture::{Event, EventPusher};
21
22use crate::activator::RcActivator;
23
24/// An event pusher wrapper that activates targets on push.
25#[derive(Clone, Debug)]
26pub struct ActivatedEventPusher<E> {
27    /// Inner event pusher.
28    pub inner: E,
29    /// Activator used to prompt receipt of event.
30    pub activator: RcActivator,
31}
32
33impl<E> ActivatedEventPusher<E> {
34    /// Create a new activated event link wrapper.
35    ///
36    /// * inner: A wrapped event pusher/iterator.
37    pub fn new(inner: E, activator: RcActivator) -> Self {
38        Self { inner, activator }
39    }
40}
41
42impl<T, D, E: EventPusher<T, D>> EventPusher<T, D> for ActivatedEventPusher<E> {
43    fn push(&mut self, event: Event<T, D>) {
44        self.inner.push(event);
45        self.activator.activate();
46    }
47}