dynamo_runtime/pipeline/nodes/sinks/
pipeline.rs

1// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License 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
16use super::*;
17use crate::Error;
18
19impl<Req: PipelineIO, Resp: PipelineIO> ServiceBackend<Req, Resp> {
20    pub fn from_engine(engine: ServiceEngine<Req, Resp>) -> Arc<Self> {
21        Arc::new(Self {
22            engine,
23            inner: SinkEdge::default(),
24        })
25    }
26}
27
28#[async_trait]
29impl<Req: PipelineIO + Sync, Resp: PipelineIO> Sink<Req> for ServiceBackend<Req, Resp> {
30    async fn on_data(&self, data: Req, _: Token) -> Result<(), Error> {
31        let stream = self.engine.generate(data).await?;
32        self.on_next(stream, Token).await
33    }
34}
35
36#[async_trait]
37impl<Req: PipelineIO, Resp: PipelineIO> Source<Resp> for ServiceBackend<Req, Resp> {
38    async fn on_next(&self, data: Resp, _: Token) -> Result<(), Error> {
39        self.inner.on_next(data, Token).await
40    }
41
42    fn set_edge(&self, edge: Edge<Resp>, _: Token) -> Result<(), PipelineError> {
43        self.inner.set_edge(edge, Token)
44    }
45}