logforth_append_async/
lib.rs

1// Copyright 2024 FastLabs Developers
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 at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! A composable appender, logging and flushing asynchronously.
16
17#![cfg_attr(docsrs, feature(doc_cfg))]
18
19use std::sync::Arc;
20
21use logforth_core::Append;
22use logforth_core::kv;
23use logforth_core::record::RecordOwned;
24
25mod append;
26mod state;
27mod worker;
28
29pub use self::append::Async;
30pub use self::append::AsyncBuilder;
31
32enum Task {
33    Log {
34        appends: Arc<[Box<dyn Append>]>,
35        record: Box<RecordOwned>,
36        diags: Vec<(kv::KeyOwned, kv::ValueOwned)>,
37    },
38    Flush {
39        appends: Arc<[Box<dyn Append>]>,
40    },
41}
42
43#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
44enum Overflow {
45    /// Blocks until the channel is not full.
46    Block,
47    /// Drops the incoming operation.
48    DropIncoming,
49}